Reputation: 11317
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();
Upvotes: 0
Views: 759
Reputation: 533472
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.
Upvotes: 2