First, I used bind()
and listen()
to bind a port to address 0.0.0.0. However, now I cannot connect.
sprintf (addrbuf, "%s-%d", SVR_ADDR, SVR_PORT);
StringToSockaddr (addrbuf, &destAddr);
if (connect(psock,(struct sockaddr *) &destAddr,sizeof(destAddr)) < 0)
die("failed to connect to server");
printf("connected to server at %s\n",getTime());
The bind()
function assigns a local address and/or port to the socket. This is well and good. The listen()
function, however, configures the socket as one that will accept connections. If you intend to use the socket to initiate a connection to a remote machine, then you should not use listen()
on it.