I am not able to explain whats been happening here for the last 45 mins or so.. I thought of posting it here:
this is my client code :
Code:
if (0 > sendto(sd,buf,strlen(buf)+1,0,
(struct sockaddr*)&server_addr,
sizeof(server_addr))){
perror("Client: Failed to send");
exit(1);
}
printf(" sent message = %s\n",buf);
if (0 >= recv(sd,buf,sizeof(buf), 0)){
perror("Unexepected response");
exit(1);
}
The sendto returns and the printf statement is executed and the client hangs.
this is the corresponding server code ;
Code:
if (0 >= recvfrom(sd,inbuf,sizeof(inbuf), 0,
(struct sockaddr*)&client_addr,
&alen)){
perror("Unexepected message");
}
printf("Server: Message received: %s !\n", inbuf);
if (0 > sendto(sd,outbuf,strlen(outbuf)+1,0,
(struct sockaddr*)&client_addr,
sizeof(client_addr))){
perror("Server: Failed to send");
}
recvfrom() is not returning.
Everything prior to this seems to be fine,I have done error checking at required places.
Also, the same thing works when I launch the server and the client on the same machines. Which means the client is not able to reach the server, when i run them on different machines. Is that right? But, the addresses must be valid.