From: Sam Roberts Date: 2004-05-08T00:00:46+09:00 Subject: Re: Encoding with TCPSocket Wrote Michael Neumann , on Fri, May 07, 2004 at 07:53:39PM +0900: > 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... At least you're getting something... What are the 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. I'd be pretty surprised if the lpr protocols used 16bit unicode! They should all be ascii. But, what is the protocol being used to talk to the "lpr-Printer", maybe it's not an lpd printer? Sam -- Sam Roberts