0

I've written a socket listener in Java that just sends some data to the client.

If I connect to the server using telnet, I want the server to send some telnet option codes. Do I just send these like normal messages?

Like, if I wanted the client to print "hello", I would do this:

PrintWriter out = new PrintWriter(clientSocket.getOutputStream());
out.print("hello");
out.flush();

But when I try to send option codes, the client just prints them. Eg, the IAC char (0xff) just gets printed as a strange y character when I do this:

PrintWriter out = new PrintWriter(clientSocket.getOutputStream());
out.print((char)0xff);
out.flush();
Matt
  • 11,157
  • 26
  • 81
  • 110

2 Answers2

2

If you use the default character encoding I would expect 0xff to be turned into two characters.

I suggest you use the plain OutputStream without a PrintWriter. That way the bytes will be sent without translation.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
2

I just answered that here

Community
  • 1
  • 1
eater
  • 2,697
  • 1
  • 21
  • 24