In this homework, we will learn how to write basic networking applications using sockets.
Write a socket client and socket server. The programs should be called "sclient" and "sserver".
sserver supports a flag -p with which you can specify the port on which it listens for incoming connections and prints "waiting for clients". When a client connets to it, it responds with appropriate messages (see the protocol) to the client and prints "client has connected". When the server has finished processing all the requests for the client, it should terminate the connection and wait for additional clients that might connect to it later. To make debugging easier, you may consider having the server print each message it receives and sends.
./sserver -p 5000 waiting for clients client has connected received: xxxxx sent: yyyyy
sclient supports the flags -p and -h with which you can specify the port and hostname for the server to which you want to connect. Upon connecting to the server, the client prints "connected to the server at port xxx host xxx". It then sends appropriate message to the server.
./sclient -p 5000 -h bayou.cs.uh.edu connected to the server at port 5000 host bayou.cs.uh.edu sent: xxxxx received: yyyyy
sclient allows a user to input text interactively. We did not standardize how the user specifies the computation to be performed to the client. You are free to design your own convention but it must be different from the protocol message. Please describe how a user should use your client in the README.
The best way to test these two programs is by running them in two different terminals and looking at the output from each program to make sure they are working correctly.
During the last few days, we converged on a text protocol to use on a socket connection between a client and a server. The protocol describes how a client sends computation requests to the server and how the server computes the results and sends the result to the client. Here is the link to the protocol specification. The protocol used by your client and server should conform to the standard. We will mix and match clients and servers from different students during testing. Because all the clients and servers use the same protocol, they should inter-operate.
Most networked services can service multiple clients at the same time. It will be nice if your server can allow multiple clients to connect to it at the same time. You may need to use non-blocking IO or forks to accomplish this. If you are feeling adventurous, you should use non-blocking IO.
Many times a single network program is a client to some services and a server of different services. To get a first hand feel of the challenges in implementing such programs, You can combine the client and the server functionality into a single program. You can call your program "socketfun". Please describe how to run "socketfun" in your README.
You will submit this assignment to the hw1 folder in the private github respository assigned to you. You will have to create the hw1 folder. We expect your assignment to be completed over at least 5 commits spread over multiple days. Please make sure each commit has a meaningful description of what was changed. Furthermore, each revision should compile. Make sure there is a README in the hw1 folder describing the author, contact information, a short description of the software, instruction on how to run it, and finally limitations of your implementation.
To grade your submission, we will run your code on bayou so you should make sure your code runs on bayou. We will git pull, change to your hw1 directory and type "make". It should generate two executables sclient and sserver.