Transport endpoint is not connected
[2009-06-20]I received this "Transport endpoint is not connected" error in a little UDP server I wrote. The lines that raised the error are these:
if ((len = recvfrom(s, buf, BUFSIZ, 0, (struct sockaddr *)&remote_addr,
&sin_size)) < 0)
{
perror("recvfrom");
return 1;
}
I happened to make my socket a connection-oriented socket, as for a TCP server. UDP makes uses a connectionless socket, so that there is much less overhead involved in sending the data. Instead of a SOCK_STREAM socket type, I had to specify the SOCK_DGRAM socket type.
--- a/udpserver.c
+++ b/udpserver.c
@@ -17,7 +17,7 @@ int main(int argc, char *argv[])
my_addr.sin_addr.s_addr = INADDR_ANY;
my_addr.sin_port = htons(8000);
- if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0)
+ if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
{
perror("socket");
return 1;
lines 1-26/26 (END)
Comments
_
Want to leave a msg?
_
No comments yet...
Comments will be moderated before shown here, so please be patient.