/************************************************************ * * helloClient.c * * Adapted from Douglas Comer's "Internetworking with TCP/IP" * by Jeff Ondich and Lauren Jantz, summer 1995. * * This client is half of a sort of "hello world" * client/server pair. The client makes a connection * to the server (at the HOST_NAME and PORT_NUMBER * defined in hello.h), and the server sends back * a snotty null-terminated character string. The * client prints this message to its own stdout. * * Note that the protocol is exceedingly simple: * * 1. Client initiates connection * 2. Server sends message, null-terminated * 3. Server closes connection * * In particular, the client never sends any actual * text to the server. If you want your client to * talk to the server, you'll need to design a more * complicated protocol, and the client will use * write() to send data to the server. * ************************************************************/ #include #include #include #include #include "tcpUtilities.h" #include "hello.h" main() { int sock, i; char c; sock = MakeConnection( HOST_NAME, PORT_NUMBER ); /* This is where the protocol implementation goes. Reading, writing, etc. From here... */ i = ReadFromSocket( sock, &c, 1 ); while( i > 0 && c != '\0' ) { putchar( c ); i = ReadFromSocket( sock, &c, 1 ); } if( i < 0 ) { fprintf( stderr, "Socket read failed: %s\n", sys_errlist[errno] ); exit(1); } /* ...to here. */ /* When all communication is done, clean up and quit. */ close( sock ); }