multithreading - How to eliminate duplicate messages from command prompt while reading from inputstreams in java -
multithreading - How to eliminate duplicate messages from command prompt while reading from inputstreams in java -
i reading xml message commnad prompt (simulator) if come in xml message , if ends >>> indicates end of message 1 i.e., when ever press come in invokes server side thread , process message . if entered 1 more xml message gives come in getting both first message , lastly message dont want first message give me solution eliminate
the below code within of thread while(true) hear message , send server while sending want latest messages only.
while(true){ if(clientsoc != null){ tempchar=br.readline(); inputstring=inputstring+tempchar; if(inputstring.endswith(">>>")){ inputstring=inputstring.replaceall(">>>",""); serverstream.write(inputstring.getbytes()); } } grab (exception e) { seek { serverstream.close(); serverstream = null; clientsoc.close(); clientsoc = null; } grab (exception e1) { clientsoc = null; serverstream = null; } } }
if got right, want when user enters string like:
"message1>>>message2>>>" this sent server:
"message2" in case, simple status check be:
if (inputstring.endswith(">>>")) { inputstring = inputstring.substring(0, inputstring.length()-3); int previousseparatoridx = inputstring.lastindexof(">>>"); if (previousseparatoridx >= 0) { inputstring = inputstring.substring(previousseparatoridx+3); } serverstream.write(inputstring.getbytes()); } java multithreading network-programming simulator
Comments
Post a Comment