This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I am writing a client server program in which the client accepts data from the user along with information on type of operation to be performed. It then passes this information to the server which performs the operation and returns the result to the client. I am using an array-list object to pass data to the server. It works fine the 1st time but after that the server doesn't accept the next array list object for the next operation. Please tell me what is wrong with my code. Thank you.
Please note that ItDoesntWorkIsUseless.(⇐click) It would help if you would TellTheDetails(⇐click) about what "the server doesn't accept it" means. What exactly are you observing? In which code in particular, at least the method, preferably the specific line or two? Is there an error message? If so, copy/paste the entire thing and indicate clearly which code is causing it.
The above code does not give me an error during run time. But when I terminate the execution of the client and server programs I get the following error messages:
1) These error messages occur in the server output window when I terminate the client first
java.net.SocketException: Connection reset
1) These error messages occur in the client output window when I terminate the server first
in the client output window :
In my server program the statement client = ss.accept() on line 21, creates a new object every time it executes . After executing once my client program is still trying to establish a connection to the old "client" object in the server program which no longer exits.
So I modified the client code and created a new instance of the socket "s" every time i want to communicate with the server. Socket "s" will then communicate with the new "client" object in the server program. I moved lines 12 -24 of the client code into the while loop beginning at line 25.