From: Michael Neumann Date: 2004-05-07T19:53:39+09:00 Subject: Re: Encoding with TCPSocket On Fri, May 07, 2004 at 07:43:55PM +0900, Michael Mueller wrote: > Hello! > > I'd like to monitor the status of a lpr-Printer with ruby. I found nice > snippet of Java Code that works fine but I'm running into problems > translating it to ruby. > Obviously my problems have to to with byte-encoding... > The Java-Code is using a socket and sending the data as a byte-Array: > > .... > Socket socket = new Socket(ip,port); > socket.getOutputStream().write(" List\n".getBytes()); > .... > > Like already said this works just like a charm... > My ruby-Snippet looks like this: > .... > socket = TCPSocket::new(server,port) > socker.print(" List\n") > .... > socket.flush > respone=socket.gets > ... > > Unfortunately all I get are some cryptic characters... > > Can somebody give me a hint how to do this in ruby? Unicode? You probably have to convert it to ASCII before printing it on screen. Take a look at the iconv module. Regards, Michael