Ce bout de code d'un serveur ne reçoit qu'un seul message d'un client. Les autres ne sont pas reçus.
Pourriez-vous me dire où est le problème ?
Merci
SOCKET s;
SOCKET a;
SOCKADDR_IN localaddr;
WSADATA wsa;
WORD v;
char data[255];
int cb,r,ca;
unsigned short nport = 1050;
unsigned long *nonbl;
unsigned long ul = 1;
nonbl = &ul;
v = MAKEWORD(2,0); // version 2.0 des Windows Sockets
if (WSAStartup(v, &wsa) != 0)
{
printf("Socket initialization error." );
getch();
exit(1);
}
else
{
s = socket(AF_INET,SOCK_STREAM,0);
if(s == INVALID_SOCKET)
printf("Unable to create socket." );
else
{
localaddr.sin_family = AF_INET;
localaddr.sin_addr.s_addr = INADDR_ANY;
localaddr.sin_port = htons(nport);
if (bind(s,(LPSOCKADDR)&localaddr,sizeof(localaddr)) == SOCKET_ERROR)
printf("Error linking socket-port." );
else
{
if (listen(s,5) == SOCKET_ERROR)
printf("Error listening to socket." );
else
{
ioctlsocket(s,FIONBIO,nonbl); //Mode non bloquant
printf("Press any key to stop...\n" );
do
{
a = accept(s,NULL,NULL);
if (a != INVALID_SOCKET)
{
strcpy(data,"" );
r = recv(a,data,sizeof(data),0);
if (r == SOCKET_ERROR)
{
if (GetLastError() == 10035) //Message vide
printf("/\n" );
else
printf("Reception error (%d).\n",GetLastError());
}
else
printf("\n%s\n",data); //Il affiche que le premier message (vide)
}
Sleep(500);
}
while(!kbhit());
}
}
shutdown(s,SD_BOTH);
shutdown(a,SD_BOTH);
cb = closesocket(s);
ca = closesocket(a);
WSACleanup();
}
}
exit(0);