Consider the following code fragment:
Code:
<...> char arrOutBuffer[]="Robtarget Data...";
n = send(s,arrOutBuffer,strlen(arrOutBuffer),0);
if (n < 0) perror("ERROR writing to socket");
char arrRespBuffer[256];
memset(arrRespBuffer,0,256);
n = recv(s,arrRespBuffer,strlen(arrRespBuffer),0);
if (n < 0) perror("ERROR reading from socket");
if (n == 0) puts("'n' is 0");
<...>
Why is it that when I send data ("Robtarget Data...") from this client to the server the server reads/displays it properly BUT when I send a response from the server the client says "'n' is 0"?
The applicable server fragment is:
Code:
<...>
int a=1;
while(a)
{
listen(sockfd,5);
clilen = sizeof(cli_addr);
newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, &clilen);
if (newsockfd < 0) error("ERROR on accept");
bzero(buffer,256);
n = read(newsockfd,buffer,255);
if (n < 0) error("ERROR reading from socket");
printf("Here is the message: %s\n",buffer);
n = write(newsockfd,"I got your message",18);
if (n < 0) error("ERROR writing to socket");
close(newsockfd);
}
<...>
The client is compiled for Win32.
The server is compiled for Linux (cygwin).
I don't have this problem when the client is written/compiled for Cygwin/Linux.