/*************************************************************************** * Copyright (C) 2010 by Michael Fischer * * fischer-michael@cs.yale.edu * * * * For use in Yale course CPSC 467b, Spring 2010 * ***************************************************************************/ Sample files for how to communicate using internet sockets. This demo contains two programs. > server port creates a welcome socket on the local node to listen at the specified port for an incoming internet connection. > client host port tries to open a connection to the given host and port. If successful, it sends data across to the server. When it finishes, both programs exit. To try them out, open two terminal windows on the same machine. Start the server in one, say, > server 4444 Then in the other window, type > client localhost 4444 The two programs should then run and print to their respective windows information about what is going on with the connection. You can also try them between different machine, replacing of course "localhost" with the host name of the machine running the server code. However, it will fail if the server machine has a firewall that blocks the specified port from incoming traffic. I've tried it between two different Zoo machines and it works there, but if you try using a server outside of the Zoo, it might or might not work for you. Notes on the code: Both programs contain sleep() calls so that one can watch them run and get some sense of the order in which things happen. Obviously a real-life program would not want to do this. I have modularized both programs to some extent, trying to separate the socket stuff from the protocol being implemented. The modularization could be better. In particular, the getWelcomeInfo() function in server.c should be made more general so that it would be useful for extracting information from the peer socket as well as the welcome socket. Other shortcomings of the code are: 1. Several of the primitives it uses such as gethostbyname() are now consider obsolete and have been replaced by newer functions. 2. The error-handling isn't very flexible. While I've tried to detect errors, they are uniformly handled by printing an error message and aborting. Despite these weaknesses, I think you will find this code useful in doing problem 5b. Please do let me know of any bugs or other problems you encounter when using it.