I have started to learn Java only. My job is to create a file server that uses threading to get files from many clients, Accepts certain orders, such as keeping the file and delete the file. I am using a custom class to serialize DataObject and send commands and any data that can be with it. The client should be made interactive in such a way that it includes the manual user input of different commands, which means that the ObjectInputStream readObject () function will not work in some time (true) loop due to an EOFException. Thread prevents readObject () until it sees the next object and then when the (true) loop starts?
The code on the server (runs for each thread separately):
Run the public null () {ObjectInputStream = Tap; ObjectOutputStream OS = Faucet; Try {new = ObjectInputStream (clientSocket.getInputStream ()); OS = New ObjectOutputStream (ClientSocket.GetOutputTream ()); Whereas (true) {input = (DataObject) is.readObject (); //System.out.println("Input read "); Output = command processor. Process (input); If (output.data == tap) {os.writeObject (output); If (output.message.compareToIgnoreCase ("RPP Bye") == 0) {clientSocket.close (); }}}}
Code on Customer:
Public Interview () {DataObject input = new DataObject (0), Output = New Data Object (0 ); Try {log = new printstream ("/ home / meher / log.txt"); InetAddress serverAddress = InetAddress.getByName ("127.0.0.1"); Socket server socket = new socket (server address, port); OS = new objectouttream (serverSockets.getOutputTream ()); = New Object InputTream (serverSocket.getInputStream ()); CommandExecuter.Hello (Production); Write (output); (Input); While (no end-user-input) {// to code this part yet / Execute commands}}
The stream ends when EOFException is thrown from readObject In your case, when the customer closes its connection, so if the client sends an object to the server and leaves immediately, then the server Reads an object and receives eofexpection next time, when it closes an object now Tried to read on the connections made.
The order in which they both agree to terminate the connection?
Comments
Post a Comment