Encoding with TCPSocket

  • Thread starter Michael Mueller
  • Start date
M

Michael Mueller

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?

Michael
 
M

Michael Neumann

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
 
S

Sam Roberts

At least you're getting something...

What are the cryptic characters?
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
 
M

Michael Mueller

Michael said:
Unicode? You probably have to convert it to ASCII before printing it on
screen. Take a look at the iconv module.

I don't think so... all I get is one char...

In the Java-Example the printer responds something like
"There are currently no jobs in the queue" (or similar)...

Regards,
Michael
 
M

Michael Mueller

At least you're getting something...

Lucky me ;-)
What are the cryptic characters?

Like I said in the response to Michael it's actually only one character...
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?

I don't think either that it's unicode...
The Java-Snippet makes no conversion at all (besides the String#toByte[]).

Regards,
Michael
 
M

Mark Hubbart

My ruby-Snippet looks like this:
....
socket = TCPSocket::new(server,port)
socker.print(" List\n")
....
socket.flush
respone=socket.gets

Does it look *exactly* like this? There is a typo in line two, you
spelled socket wrong.

Otherwise, have you tried manually telnetting to that host:port? Type
in "List", hit return, and see what happens. (I think any OS nowadays
comes with a telnet app, right?)

If I had an lpr server, I'd check it, but I don't. :)

HTH,
--Mark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,967
Messages
2,570,148
Members
46,694
Latest member
LetaCadwal

Latest Threads

Top