1

I'm developing a client/server program using socket programming.

I got stuck where I want the server to show the character as soon as I type a character on client's side(i.e. taking input from a client before enter is pressed).

Need help! Thanks in advance.

Yu Zhang
  • 2,037
  • 6
  • 28
  • 42
  • You can put a buffered reader on top of your socket input stream. It should block until necessary bytes are sent over the wire. – Michael-O Oct 25 '15 at 08:43
  • 'Real-time' has a specific meaning in computing, and this isn't it. Don't misuse standard terminology. – user207421 Oct 25 '15 at 09:05
  • I want such that, while i type on client side, server should feel that it is writing the same text on it's side. Isn't it called real time? –  Oct 25 '15 at 12:46

1 Answers1

-2

I assume you are using printwriter and buffered reader?

you would need to do something like

out.println(textField.getText());
textField.setText("");

Where textField is the field where the user is typing and out is your printwriter.

On the server you need to capture that text. so something like

String input = in.readLine();

Where in is your bufferedreader. The tricky part is doing it as the user types, you need to detect the change in the textfield and pipe the information every time the characters change. http://www.coderanch.com/t/609096/java/java/Realtime-update-changing-JTextField this is a very good tutorial on that subject.

  • `readLine()` blocks until a line terminator or EOS has been reached, or an exception has been thrown. The OP specifically wants one character at a time. – user207421 Oct 25 '15 at 09:06
  • Thanks dear! Can you explain this with a snippet or provide a reference link. I think this will solve my query. Thanks again @EJP –  Oct 25 '15 at 12:49