Click here to Skip to main content
16,008,954 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Why does the line "delete [] player_data_array;" give a Debug Error Pin
Mark Salsbery29-Jun-08 11:49
Mark Salsbery29-Jun-08 11:49 
GeneralRe: Why does the line "delete [] player_data_array;" give a Debug Error Pin
tippex11-Jul-08 3:27
tippex11-Jul-08 3:27 
GeneralRe: Why does the line "delete [] player_data_array;" give a Debug Error Pin
Mark Salsbery1-Jul-08 6:35
Mark Salsbery1-Jul-08 6:35 
GeneralRe: Why does the line "delete [] player_data_array;" give a Debug Error Pin
Stephen Hewitt29-Jun-08 15:15
Stephen Hewitt29-Jun-08 15:15 
QuestionIssue with calling the MessageBox Windows API from a DLL Pin
jbf15429-Jun-08 8:19
jbf15429-Jun-08 8:19 
AnswerRe: Issue with calling the MessageBox Windows API from a DLL Pin
dave_mm04-Dec-08 10:03
dave_mm04-Dec-08 10:03 
GeneralRe: Issue with calling the MessageBox Windows API from a DLL Pin
jbf1544-Dec-08 16:23
jbf1544-Dec-08 16:23 
QuestionNetwork programming (problem)???my server software is giving connection established but my client software is giving socket init failed Pin
bodhi201629-Jun-08 6:25
bodhi201629-Jun-08 6:25 
My srever software:-
#include<windows.h>
#include<iostream>
#include<winsock2.h>
#include<conio.h>
int main()
{
WSAData wsadata;
if (WSAStartup(MAKEWORD(2,0),&wsadata)!=0)
{std::cout<<"winsock startup failed\n"<<WSAGetLastError();
WSACleanup();
return -1;
}
std::cout<<"winsock startup is succes\n";
SOCKET servsock=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
if(servsock ==INVALID_SOCKET)
{std::cout<<"socket init failed\n";
WSACleanup();
return -1;
}
std::cout<<"socket init\n";
sockaddr_in sin;
sin.sin_port=htons(80);
sin.sin_addr.s_addr=INADDR_ANY;
sin.sin_family=AF_INET;
if (bind(servsock,(sockaddr*)&sin,sizeof(sin))==SOCKET_ERROR)
{std::cout<<"FAILED TO BIND"<<WSAGetLastError();
WSACleanup();
return -1;
}
std::cout<<"Bind successful!\n";
//WSACleanup();
//while (listen(servsock,1)==SOCKET_ERROR);
SOCKET b=listen(servsock,1);
if (b==SOCKET_ERROR)
{
std::cout<<"error"<<WSAGetLastError();
getch();
return 0;
}
else
//int client;
{int len = sizeof(sin);
SOCKET client=accept( servsock,(sockaddr*)&sin,&len);
if (client==SOCKET_ERROR)
{
std::cout<<"error"<<WSAGetLastError();
}
//SOCKET client;
// while(client=accept( servsock,(sockaddr*)&sin,&len)==SOCKET_ERROR)
std::cout<<"Connection established!\n";
closesocket(client);
closesocket(servsock);
WSACleanup();
getch();
return 0;
}
}
One of my IRC friend said that my server software is terminating the accept() function quickly so my client software was giving socket init failed inspite of the fact that server software was giving "connection established ".What i am interpreting from this is that the accept() function of the server software is not returning SOCKET_ERROR
otherwise it would not have given "connection established " because my accept function is in "if" statement.But if i keep my Accept function within the while statement (lines 48 and 49)my server software gives bind successful and stops and seems as if goes into an infinite loop or something
.
My client softeware :-
#include<windows.h>
#include<iostream>
#include<winsock2.h>
#include<conio.h>
//#include<stdio.h>
int main()
{
WSAData wsadata;
if(WSAStartup(MAKEWORD(2,0),&wsadata)!=0)
{
std::cout<<"1:(startup failed\n"<<WSAGetLastError();
WSACleanup();
return -1;
}
else
{
std::cout<<"2Smile | :) Socket Init Success\n";
}
SOCKET mysock=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
if(mysock==INVALID_SOCKET )
{
std::cout<<"3:(Socket Init Failed\n";
WSACleanup();
return -1;
}

else
{
std::cout<<"4Smile | :) Socket Init Success\n";
sockaddr_in sin;
sin.sin_port=htons(80);
sin.sin_addr.s_addr=inet_addr("127.0.0.1");
sin.sin_family=AF_INET;
// if (connect(mysock,(sockaddr*)&sin,sizeof(sin))==SOCKET_ERROR)
//{std::cout<<"5:(Socket Init FAiled\n"<<WSAGetLastError();
// getch();
//WSACleanup();
// getch();
//return -1;
//}
int a=connect(mysock,(sockaddr*)&sin,sizeof(sin));
if(a=SOCKET_ERROR)
{std::cout<<"5Smile | :) Socket Init FAiled\n"<<WSAGetLastError();
//getch();
WSACleanup();
//return -1;
getch();
//return 0;
}

else
std::cout<<"connection sucessful";
closesocket(mysock);

getch();
return 0;
}
}
<b>My client software is giving an output of "Socket Init FAiled"
and in place of WSAGetLastError() it is giving error "0".i reffered to msdn there is no such thing as error 0</b>
AnswerRe: Network programming (problem)???my server software is giving connection established but my client software is giving socket init failed Pin
Mark Salsbery29-Jun-08 8:18
Mark Salsbery29-Jun-08 8:18 
QuestionNeed Help... Pin
Rozz1829-Jun-08 0:36
Rozz1829-Jun-08 0:36 
AnswerRe: Need Help... Pin
rp_suman29-Jun-08 5:00
rp_suman29-Jun-08 5:00 
AnswerRe: Need Help... Pin
Baltoro29-Jun-08 11:37
Baltoro29-Jun-08 11:37 
GeneralRe: Need Help... Pin
Rozz1830-Jun-08 11:39
Rozz1830-Jun-08 11:39 
QuestionXP problem Pin
RomTibi28-Jun-08 19:48
RomTibi28-Jun-08 19:48 
AnswerRe: XP problem Pin
rp_suman29-Jun-08 4:52
rp_suman29-Jun-08 4:52 
GeneralRe: XP problem Pin
RomTibi6-Jul-08 5:48
RomTibi6-Jul-08 5:48 
AnswerRe: XP problem Pin
Ștefan-Mihai MOGA29-Jun-08 5:01
professionalȘtefan-Mihai MOGA29-Jun-08 5:01 
GeneralRe: XP problem Pin
RomTibi6-Jul-08 5:49
RomTibi6-Jul-08 5:49 
QuestionHow to get Thread State Pin
SalarSoft28-Jun-08 18:21
SalarSoft28-Jun-08 18:21 
AnswerRe: How to get Thread State Pin
rp_suman29-Jun-08 5:24
rp_suman29-Jun-08 5:24 
AnswerRe: How to get Thread State Pin
Mark Salsbery29-Jun-08 8:40
Mark Salsbery29-Jun-08 8:40 
GeneralRe: How to get Thread State Pin
SalarSoft29-Jun-08 18:20
SalarSoft29-Jun-08 18:20 
AnswerRe: How to get Thread State Pin
SalarSoft30-Jun-08 19:41
SalarSoft30-Jun-08 19:41 
Questionenduring object in Visual Studion Pin
bkelly1328-Jun-08 7:15
bkelly1328-Jun-08 7:15 
AnswerRe: enduring object in Visual Studion Pin
CPallini28-Jun-08 7:30
mveCPallini28-Jun-08 7:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.