Need help implementing Client/Server programming in C/C++
Hi, I need help in implementing Client/Server program in C/C++. I really hope someone can help me with it. I'm in urgent for my due project. Following is what should be implemented:
I am required to program a multiple servers/clients files system using TCP/IP unicast communication on SUN workstations in C or C++. In this system, there is a boot server, whose IP address and port number are known by the non-boot servers and clients. The boot server has a certain number of files (say 10 files).
A non-boot server can join the system by registering with the boot server at any time it wants. The boot server will randomly assign several files (say 3 files) to the server. Note that there may be multiple non-boot servers in the system, whose IP addresses and port numbers are maintained by the boot server. We assume a non-boot server will never leave the system after joining.
A client can also join the system by registering with the boot server at any time it wants. The boot server will randomly select an existing non-boot server to be the host-server of the client, and forward the selected serverís IP address and port number to the client. Note that there may be multiple clients in the system. One non-boot server can be the host-server of multiple clients.
A client can download a file from its host-server by sending a request with the file name to its host-server (assume the client knows the file name). If the host-server has the requested file, it will directly forward the file to the client. Otherwise, it will get the file from the boot server and forward to the client. In this case, the host-server will store the file for the future accesses by its clients. The client will print the file on the screen once it receives the file.
My question is do we create the 10 files first in the directory of the C/C++ codes? But then, how can the main boot server randomly distribute the files to the non boot server? In this case, sample implementation might help me more than just the theory. I hope someone can give me some sample codes. I have known how to set up TCP/IP connection between server and client. However, in this project, multiple clients are allowed to access the non boot server concurrently. I suppose I have to implement the multithreaded server program. I am really blank in this part. Can someone please give me examples of the code? And about the problem, boot server will randomly pick non boot server to be assigned to the client, how is it implemented? And how can boot server creates multiple nonboot server randomly? How can we make it random..or we just create as many as we want? Is it using fork to create non boot server? I really hope someone can help me. I am really in need of help. I will appreciate very much if someone can really help me. Or if possible, please e-mail me. Thank you.
Do you have the W. Richard Stevens book Unix Network Programming Vol I (http://www.kohala.com/start/unpv12e.html). He discusses several protocols and has a lot of sample code. Even if you don't have the book, the source code for all the example programs are available online at the above link. Hope this helps
P.S. Stevens has passed on unfortunately, and his code used a couple of #defines which were later renamed by later RFCs. Hence, the code that you download may not compile on current *NIX systems, without a minor patch. See the comments on this thread for how to patch it.
really thank you so much that you reply my message. I have searched on the link and try to see the sample codes. Is there any sample code for multithreaded server? And can someone give me a hint on how to create several non-boot server from one boot server? Is it using fork or non-boot server is independently built? And how to build multiple clients? I am still not getting it right now. Really need your help. Thanks.
If you've downloaded his code, try looking at the code within the unpv12e/tcpcliserv and unpv12e/udpcliserv/ directories. You'll find several examples of using multithreaded servers as well as client code there.
P.S. If you haven't found his code, this is the link you want
thanks for the quick response. i'll take a look at it first. I will ask again if I don't understand. Anyway, thank you very much. I'm really glad to find out this forum.
Hi, I have a problem with the write and read part of the socket. I don't know how to handle multiple messages sent by clients. Do we need to make multiple sockets and put each message in each socket? If not, then how does the server read the messages? How can the server distinguish the 1st message, 2nd message and so on? And how can it be implemented such that the reading from socket would only be carried out after the writing to socket. I am stuck right now. I can't handle the reading of messages. It seems the IP messages and the data messages is combined in the socket. Do we need to make a null terminated in each message? Hope someone can help me.