java - client socket issues when reading -


I am having a real problem in trying to solve my problem and hope you guys can help. I have seen many socket examples online but are unable to modify them for my use. Tbh, im also struggling to get a sense of chairs, I have been successful in amending so far.

My problem, I believe my client is not reading the message coming from the program server, can someone ask me to demonstrate using my example where I am going I'm wrong. Something like this in my mind says that my customer socket stops before an opportunity to read an incoming message. Maybe the customer is waiting to wait until the message is received? If it is necessary to wait, how will it be achieved? thank you in advanced.

Customers:

  Try {socket socket = new socket ("localhost", 55555); PrintWriter = New PrintWriter (socket.getOutputStream (), true); Out.write (score); BufferedReader = new in BufferedReader (new InputStreamReader (socket.getInputStream ())); String rank = in.readLine (); Println (rank); In.close (); Out.close (); Socket.close (); } Hold (exception e) {System.out.print ("woo! It is not working! \ N"); }  

Server:

  Try {System.out.println ("Waiting for the client to connect ....."); ServerSocket Server = New ServerSetket (55555); Socket socket = server.accept (); System.out.print ("The client is connected! \ N"); BufferedReader = new in BufferedReader (new InputStreamReader (socket.getInputStream ())); String score = (in.readLine ()); Scor = Long. From Long (score); Leaderboard (); ///// A method which uses long periods for ranking - A STRING value is printed on the entered number = new print witter (socket.getOutputStream () is true); System.out.print ("Sending Rank:" + Rank); Out.write (rank); Out.close (); Socket.close (); Server.close (); } Hold (exception e) {System.out.print ("Whoops! It did not work! \ N") 'Enter the code here'; }  

Your code looks ok ...

Client Using the program, you are writing a line:

 . Outlined (score);  

You can change this:

  out.println (score);  

To take care of the answer, do the same on your server's programs:

  out.println (rank);  

Let me know how you go .. If this helps, do not deny / mark it as a solution;) Cheers

(BTW , What causes the problem as: in.read'LINE '() is waiting for the string value to save for the end of a line or Newline (\ n). If you use the outside Type () if you type the new row (\ n) manually for more string reading. Read the if you use the outside printline, then \ n automatically added to each string sent.

The readline method in your program is a newline character, which is why your program Stuck in that place)


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -