Communication problem between client/server

M

Michelle

Hi all,

I have a client/server setup which I would like it to communicate
as follows:

Server:
Loop
Write something to client via writeUTF() method
(for example: loop #1 - write "A"; loop #2 - write "B")
Get input from the client via readUTF() method
(for example: loop #1 - get "X"; loop #2 - get "Y")
End loop

Client:
Loop
Read something from server via readUTF() method
(for example: loop #1 - read "A"; loop #2 - read "B")
prompt for input of something (I'm using System.in.read())
(for example: loop #1 - entered "X"; loop #2 - entered "Y")
End loop;

However, when I use System.in.read() to entered X and pressed
<CR>, the program seems sending both "X" and "<CR>" back
to the server and in loop#2, program just don't stop and prompt
for input.

Any idea?
 
K

Kevin McMurtrie

Michelle said:
Hi all,

I have a client/server setup which I would like it to communicate
as follows:

Server:
Loop
Write something to client via writeUTF() method
(for example: loop #1 - write "A"; loop #2 - write "B")
Get input from the client via readUTF() method
(for example: loop #1 - get "X"; loop #2 - get "Y")
End loop

Client:
Loop
Read something from server via readUTF() method
(for example: loop #1 - read "A"; loop #2 - read "B")
prompt for input of something (I'm using System.in.read())
(for example: loop #1 - entered "X"; loop #2 - entered "Y")
End loop;

However, when I use System.in.read() to entered X and pressed
<CR>, the program seems sending both "X" and "<CR>" back
to the server and in loop#2, program just don't stop and prompt
for input.

Any idea?

Writing to a stream is not guaranteed to send all data through to the
other side until you call flush() or close(). Most data conversion
streams are buffered to some degree. A SocketOutputStream may or may
not be buffered, depending on the OS.
 
M

Michelle

Kevin McMurtrie said:
Writing to a stream is not guaranteed to send all data through to the
other side until you call flush() or close(). Most data conversion
streams are buffered to some degree. A SocketOutputStream may or may
not be buffered, depending on the OS.

However in my case, the loop#1 seems send back both the "A" and "CR"
to the server side so that in loop#2, it does not prompt for further input.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top