Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.3 4.3bsd-beta 6/6/85; site wucs.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxr!mhuxn!ihnp4!wucs!nz From: nz@wucs.UUCP (Neal Ziring) Newsgroups: net.unix Subject: Re: AF_INET sockets, code examples needed. Message-ID: <1004@wucs.UUCP> Date: Thu, 27-Jun-85 01:48:16 EDT Article-I.D.: wucs.1004 Posted: Thu Jun 27 01:48:16 1985 Date-Received: Fri, 28-Jun-85 03:21:45 EDT References: <240@greipa.UUCP> Organization: Eng. Computer Lab, Wash. U. Lines: 49 Summary: Some code that always helps my clients work. In article <240@greipa.UUCP>, jordan@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@wucs.UUCP