[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Getting incomplete reply from socket

Greg Vaughn

10/13/2003 4:49:00 AM

I must be missing something. I'm still fairly new to ruby, so I
shouldn't be too surprised. My first real ruby 'project' is to script
telling my wireless router to connect and disconnect the modem. I've
got that part working, but I wanted to add a feature to poll the log of
the router until I actually get connected.

I should mention that this router does not strictly follow the http
spec. In some cases it returns no http header, and when it does, the
content length is usually wrong. These seem to throw the HTTP library
for a loop (curl too), so I dropped down to the socket library for my
work.

When I access the log on the router, here's the type of thing it really
returns (captured via netcat):
HTTP/1.0 200 OK
Pragma: no-cache
Content-Length: 24
Content-Type: application/octet-stream

2003/10/10 20:25:27 Modem starts to dial up to *70,xxx-xxx-xxxx
2003/10/10 20:25:28 Wait for modem's response.
2003/10/10 20:26:37 Since modem has no response. Hang up!
2003/10/10 20:26:42 Modem starts to dial up to *70,xxx-xxx-xxxx
2003/10/10 20:26:43 Wait for modem's response.
2003/10/10 20:27:12 Modem connection baud rate: 48000
2003/10/10 20:27:12 Modem starts PPP.
2003/10/10 20:27:12 Username and Password : OK
2003/10/10 20:27:16 Modem get IP : yy.yy.yy.yy


Here's the ruby I'm using to call it:
def networkSend(tosend)
reply = ""
TCPSocket.open($host, $port) do |aSession|
aSession.send(tosend, 0)
reply = aSession.recv(10000)
end
return reply
end

This is what I get out of ruby (with a trailing blank line):
HTTP/1.0 200 OK
Pragma: no-cache
Content-Length: 24
Content-Type: application/octet-stream


It seems to be missing the body of the message. Does anyone know why?

This happens both on ruby 1.6.7 and 1.8 on Mac OS X.

-Greg Vaughn


1 Answer

Frank Mitchell

10/13/2003 10:24:00 AM

0

Greg Vaughn wrote:
> When I access the log on the router, here's the type of thing it really
> returns (captured via netcat):
> HTTP/1.0 200 OK
> Pragma: no-cache
> Content-Length: 24
> Content-Type: application/octet-stream
>
> 2003/10/10 20:25:27 Modem starts to dial up to *70,xxx-xxx-xxxx
> 2003/10/10 20:25:28 Wait for modem's response.
> 2003/10/10 20:26:37 Since modem has no response. Hang up!
> 2003/10/10 20:26:42 Modem starts to dial up to *70,xxx-xxx-xxxx
> 2003/10/10 20:26:43 Wait for modem's response.
> 2003/10/10 20:27:12 Modem connection baud rate: 48000
> 2003/10/10 20:27:12 Modem starts PPP.
> 2003/10/10 20:27:12 Username and Password : OK
> 2003/10/10 20:27:16 Modem get IP : yy.yy.yy.yy
>
> Here's the ruby I'm using to call it:
> def networkSend(tosend)
> reply = ""
> TCPSocket.open($host, $port) do |aSession|
> aSession.send(tosend, 0)
> reply = aSession.recv(10000)
> end
> return reply
> end
>
> This is what I get out of ruby (with a trailing blank line):
> HTTP/1.0 200 OK
> Pragma: no-cache
> Content-Length: 24
> Content-Type: application/octet-stream
>
> It seems to be missing the body of the message. Does anyone know why?
>
> This happens both on ruby 1.6.7 and 1.8 on Mac OS X.

Hm. I haven't really used Ruby sockets, but this smells like a more
general TCP/IP problem. If your server sends the reply as two TCP/IP
packets, the line

reply = aSession.recv(10000)

will probably read only the first packet (header), regarless of how big
you make the constant. Instead, read data in a loop, until the socket
closes (assuming this server closes the socket after it sends the end of
the log).

--
Frank Mitchell (frankm each bayarea period net)

Please avoid sending me Word or PowerPoint attachments.
See http://www.fsf.org/philosophy/no-word-attach...