Communication Lag :(
I managed to connect two pcs using the ObjectInput/Output stream though I can send data over the socket there is a communication lag. and the thing that makes me suspect its a bug is that Its consistent. It keeps skipping every other message.
Take for example I send the message the sequence of messages:
* Hello (1)
* How are you? (2)
* What is new? (3)
*Where are you now? (4)
* I see..(5)
Then only(1) + (3) + (5) would show up on the other screen...
I have read about sockets and its all thesame information over and over again...and I knwo I am writting it exactly thesame.
Are you using flush()? Streams of all sorts have buffers, and they tend not to write until the buffer is filled. flush() forces the write.
yeah, I tried using flush()..its still thesame problem.
Also I think I should mention that it is a thread that listens and writes the messages to, while another thread that handles the connection is running too. Would it happen to be because the Operating system is switching between the threads and misses some inputs?
No, not by itself. The lag sounds like a time out. Look at the API for your streams. It sounds like the first transmit gets through, and then the second one fails somehow, which leads to a reset and starts the process over. You may have to create a new ObjectInput/OutputStream after each use, or reset them. Again, read the API carefully.
Thanks alot , I would try that :) somehow I have a feeling it would work..
@Steve11235: I tried but it didn't work ....it sparked an error.
Though there is something that also made me convinced that its a mistake from me, because it i clicked a button to send a message to the other screen and each time I did it printed an error on the screen ,showing that it not a sync problem. would try reading up...
I finally got whats wrong. it was my mistake all along...
I used to have this code ...
it turns out the "if" that i was using to dodge null pointer exception was the problem, I just used the try and catch inside the loop directly on the code and it worked out...