tcp client/server pair can send data only one way
Consider the following code fragment:
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"?
<...> char arrOutBuffer="Robtarget Data...";
n = send(s,arrOutBuffer,strlen(arrOutBuffer),0);
if (n < 0) perror("ERROR writing to socket");
n = recv(s,arrRespBuffer,strlen(arrRespBuffer),0);
if (n < 0) perror("ERROR reading from socket");
if (n == 0) puts("'n' is 0");
The applicable server fragment is:
The client is compiled for Win32.
clilen = sizeof(cli_addr);
newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, &clilen);
if (newsockfd < 0) error("ERROR on accept");
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");
The server is compiled for Linux (cygwin).
I don't have this problem when the client is written/compiled for Cygwin/Linux.