Lecture Saying that:
I am generally expecting most of you to work n java.If you prefer to use c/c++ version of the programs,you may,but the assistance in the lab sessions will be very much geared towards java user.
compile both the client and the server programs.open two shell windows on different machines(using e.g ssh or putty to log into another machine).run the server onn one machine,then run the client on the another machine and let it connect to the server.type text into the client window and check whether it is indeed displayed in the server window.if you run the client and the serveron the same machine then use localhost as the address to which the client should connect.
YOUR TASK IS AS FOLLOWS :
The server is written in such a way that only one client can connect to it at any time.modify the server sothat several clients can be connected to it(and later disconnect from it) simultaneously.In other words,the server should be able to maintain open TCP connections to several clients.
when a client sends a string to the server ,the server should display the string and send it to all other clients that are currently connected it.each client should do two things: strings entered via the keyboard should be sent to the server, and strings received from the server should be displayed on the console.
SOME EXTRA INFORMATION:
There are two normal ways for dealing with several open connections: The most common method is to use threads(sothat each connection is handled by a different thread).An alternative is to use non-blocking i/o (sothat,for example,calling a function to receive data over a socket will not block indefinitely if no data arrives).
in java,facilities for non-blocking i/o are available in the java.nio.* packages.In particular ,the classes ServerSocketChannel and ServerChannel provide non-blocking TCP sockets ,and Selector can be used to wait for one of several sockets to change status.
In c/c++ , a socket can be put into non-blocking mode using fcntl. Waiting for one of several sockets to change status can be implemented efficiently using select or poll.
Refer to UNIX manpages for descriptions of the socket operations and operations such as select ,poll,fcntl etc. in c/c++ or refer to the java API documentation for information about the java.net and java.nio packages.