AF_INET sockets, code examples needed.
Neal Ziring
nz at wucs.UUCP
Thu Jun 27 15:48:16 AEST 1985
In article <240 at greipa.UUCP>, jordan at greipa.UUCP (Jordan K. Hubbard) writes:
> Thank you for all the responses on my AF_UNIX domain socket
> question. selecting the accepting socket works nicely.
>
> Now for another question, I've built a simplistic server/client model
> for testing AF_INET sockets and it doesn't work.. I've declared the
> server as a 'service' and done the appropriate get host and server
> calls and bound the socket. Connections are accepted, but the accept
> call returns a fd with a value of zero!
My code never works unless I bind a name to the client's socket.
Actually, this is not surprising, because a name is required.
Here is part of the code I use to bind a name to a socket:
do {
sin_sync.sin_port = htons( (--portnum));
} while(
bind( sock_num, (char *)&sin_sync, sizeof(sin_sync) ) < 0
&&
portnum > 2);
if (portnum <= 2) {
PERROR("timesync: bind");
msg("timesync: couldn't name my socket! Heck!\n");
return(-4);
}
I think that if you bind an address to your client's socket, your
code may work.
Also, it sometimes helps to set options on the client's socket ONLY:
if ( setsockopt( sock_num, SOL_SOCKET, SO_DEBUG, (char *) 0,0) <0) {
close( sock_num );
return(-1);
}
Hope this is helpful. If you would like complete copies of the (working)
programs from which these fragments were extracted, just drop me a letter.
...nz
--
========
...nz (ECL - we're here to provide superior computing)
Washington University Engineering Computer Laboratory
old style: ... ihnp4!wucs!nz
new style: nz at wucs.UUCP
More information about the Comp.unix
mailing list