multithreading - How to eliminate duplicate messages from command prompt while reading from inputstreams in java -


I'm reading an XML message from the CMNead prompt (simulator) if I put an XML message and if it's with Android Ends & gt; & Gt; Indicates the end of the message, that is, whenever I enter, it invites the server side thread and processes the message. If I put another XML message then I am getting both the message and the last message, but I do not want the first message, so let me solve it.

The code below is inside the thread While (true) it will always listen to the message and send it to the server, while sending, I only need a temporary message.

  while (true) {if (clientsoc! = Null) {tempchar = br.readline (); Inputstring = inputstring + tempchar; If (inputstring.endsWith ("> gt;>")) {inputstring = inputstring.replaceAll (">>", ""); Serverstream.write (inputstring.getBytes ()); }} Hold (exception e) {try {serverstream.close ()} serverstream = faucet; Clientsoc.close (); Clientsoc = Null; } Hold (exception E1) {clientsoc = null; Serverstream = faucet; }}}}    

If I found it right, you want it That's when the user like a string:

  "Message 1>> Message 2>>>   

It has been sent to the server:

  "message2"   

In this case, the situation is very simple The check may be:

  if (inputstring.endsWith (">>>>)) {inputstring = inputstring.substring (0, inputstrung.length () - 3 ); Int last esperator idx = inputstring.lindexoff ("> gt;>); If (previous asperator idx> = 0) {inputstring = inputstring.substring (previous asperator idx + 3); } Serverstream.write (inputstring.getBytes ()); }    

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -