Socket programming examples wanted

Paul Moody paul at cscnj.csc.COM
Fri Oct 20 05:15:22 AEST 1989


In article <101 at tw-rnd.SanDiego.NCR.COM>, johnl at tw-rnd.SanDiego.NCR.COM (johnl) writes:
> 
> 	I would like to get some sample code illustrating the use of sockets
> in a client/server model.  I am using Internet domain, stream sockets and am
> In my example code:
> 4. The server (using select) detects the incoming message,
>                           calls accept to get a new file descriptor,
>                           forks a child which calls recv to read the message,
>                           child closes it's (new) socket and dies.

I dont know what flavor of tcp/ip you are using, but all three that
we work with say 'DONT USE SELECT'. Instead use a blocking accept
and set an alarm. 
eg:

		/* accept new connections */
			timeout = FALSE;
			signal(SIGALRM,clockwatch);
			alarm(1);
			if ((news=accept(s,&newaddr,&newaddrlen)) == -1)
			{	if (timeout == FALSE)
					abort("accept failed");
			}
			else
			{
				makechild(news);
			}
			alarm(0);
-- 
Paul Moody			UUCP: rutgers!cscnj!paul 
Computer Sciences Corporation
# the opinions expressed are entirely imaginary			#



More information about the Comp.unix.questions mailing list