java - Sending text with new lines over network -


I am trying to send text with new lines on a network in Java. For example:

"Hello \ nIt's a new line"

Here's my code that I'm using for clients: / P>

  socket kkSocket = null; PrintWriter = Null Out; Buffet = thread in the thread; / * Connect to server here * / BufferedReader stdIn = new BufferedReader (New InputStreamReader (System.in)); String to server; User of string; While (= cesar = in.readLine ()) = = null {System.out.print ("server:" + server); if (server.exe ("by.")) {Brake;} user = stdIn .readLine (); if (user! = Null) {System.out.print ("client:" + user); out.println (fromUser);}} Out.close (); in.close (); stdIn .close (); kkSocket.close ();   

And here is the code that I am using for the server:

  / * Here the server Connect to * / printWriter = New printWriter (out of the client), In the BufferedReader = New BufferedReader (new InputStreamReader (clientSocket.getInputStream ()); String input line, Outputline; Protocol Ol kkp = new protocol (); OutputLine = kkp.processInput (null); out.println (outputLine); while ((inputLine = in.readline ()) = null) {outputLine = kkp.processInput (inputLine); out .println (outputLine); if (outputLine.equals ("by.") Break;}   

but it only returns the first line

Does anyone correct me Can point in the direction so that I can use new lines?

The first thing to note is that readLine () method line Using the terminators, \ n due to being one of them, is not included in the remaining text, for this to be indented, you must change the readLine () method again. In your case, I have used the read (four [] CBF, int, off lane method which reads char [] as follows: < / P>

readLine () of Abuse instead of read (char [] cbuf, int off, int len) instead to use

  char [] Cbuf = new char [1024]; While (in.read (cbuf, 0, cbuf.length)! = Null) {from Server = new String (cbuf); System.out.print ("server:" + server); If (server.quil ("by.")) {Break; } To user = stdIn.readLine (); If (user! = Null) {System.out.print ("Client:" + User); Out.println (fromUser); }}    

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -