int main()
{
CRc5 dec;
WSADATA wsaData;
int err;
if((err =WSAStartup(0x0002, &wsaData)) !=0)
{
printf("Init WSAStartup() failed[%d].", err);
return false;
}
//socket structure
SOCKADDR_IN addr;//addr = socket structure
int addrlen = sizeof(addr);
//making the socket
SOCKET sListen;//listenig to the incoming connections
SOCKET sConnect;//operating the connection
//setuping the socket
sConnect=socket(AF_INET,SOCK_STREAM,NULL);//sock_stream = that the socket is a connection_oriented
//setup the structure
addr.sin_addr.s_addr=inet_addr("127.0.0.1");// ip of the connection
addr.sin_family= AF_INET;
//seting the prot
addr.sin_port= htons(9958);
//sertuping Listen socket
sListen=socket(AF_INET,SOCK_STREAM,NULL);
//binding connection
bind(sListen,(SOCKADDR*)&addr,sizeof(addr));
//listening
listen(sListen,SOMAXCONN);//listing with out any limit
printf("Attempting Socket Connection\n");
printf("Wating For An Incoming Connection!\n");
for(;;)
{
if((sConnect=accept(sListen,(SOCKADDR*)&addr,&addrlen)) != INVALID_SOCKET)
{
char buf[500];
int len = strlen(buf);
recv(sConnect,buf,len,0);
}
else
{
printf("Error accepting %d\n",WSAGetLastError());
}
}
}
但它没有收到任何东西,它从游戏客户端接受套接字,然后什么也没发生,为什么!!?