The networking example we went over in class consisted of two different programs, one that implemented a server and the other that implemented the client. Another popular networking model is peer-to-peer. In this model a program can act as either the client or the server (or both). The most simple way to implement this is to give the user of the program the choice of whether to run the program as client or server when the program first begins. If the user chooses server, it should create a server socket and print the ip address that it is waiting for a client connection on. If the user chooses client, the program should query the user for the ip address of the server it should connect to. In either case the result should be the same, a PrintWriter and a BufferedReader that are connected to another computer running the same program.
Create a simple, command-line, peer-to-peer chat program. Every time the program reads text from the socket it should display it to the command line. Every time the user types text it should write it to the socket. In order to both read the input from the user and input from the socket the program will need to create a thread. You can do this either with the Thread class you learned last week or with the Timer class you learned at the beginning of the semester.
Create a peer-to-peer two player version of the board game Connect Four. This is more difficult than the chat program because each player of the game will have their own copy of the game state (in order to draw it for the user), that must be kept in sync. You can use your code from the chat program to establish the network connection between two computers. You will need to devise how to encode changes in the state of board that will be communicated to the opponent's board. The code in the files ConnectFour.java and ConnectFourBoard.java contain code that will display a connect four board.
To submit your code: Tar the files in your lab12 directory and copy the tgz file to the directory /home/staff/bouchard/CPSC170A/lab12. Be sure to name the tar file with your names, not lab12.tgz.