/************************************************************ * * helloConcurrent.c * * Adapted from Douglas Comer's "Internetworking with TCP/IP" * by Jeff Ondich and Lauren Jantz, summer 1995. * * This program needs to be commented. * ************************************************************/ #include #include #include #include #include #include "tcpUtilities.h" #include "hello.h" main() { int masterSocket, slaveSocket; struct sockaddr_in sin; int addressLength = sizeof(sin); char message[100] = "\n\nDon't bug me. I'm busy.\n\n"; char name[100]; /* Start listening at the indicated port. */ masterSocket = SetUpPassiveSocket( PORT_NUMBER, Q_LENGTH ); while( 1 ) { /* Answer the phone. */ slaveSocket = accept( masterSocket, (struct sockaddr *)&sin, &addressLength ); if( slaveSocket < 0 ) { fprintf( stderr, "Hello: accept failed: %s\n", sys_errlist[errno] ); exit(1); } /* The protocol implementation goes from here... */ /* Log the connection. */ GetPeerHostName( slaveSocket, name ); fprintf( stderr, "\nProcessed request from %s\n", name ); /* Send the message. */ write( slaveSocket, message, strlen(message)+1 ); /* ...to here. */ /* Hang up. */ close( slaveSocket ); } }