reading from sockets

AlbaClause you at cogeco.ca
Thu Aug 10 21:05:14 EDT 2006


AndrewTK wrote:

> Hello,
> 
> I'm trying to read data from a socket and I'm not seeing what I'm
> expecting.... it seems to skip the first line of data. I am new to
> Python and just trying to test what I can do with it... and it's not
> looking pretty.
> 
> 
> I have some Python code:
> [------------------------------
> #! /usr/bin/python
> 
> import socket
> 
> s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
> s.connect( ("localhost",54321) );
> s.send("hello")
> data = s.recv(1024)
> while len(data) > 0:
> print repr(data) # the first print of data always seems to "ignore"
> the first line of data...
> data = s.recv(1024)
> ------------------------------]

I'm new to Python too, but I'd have to agree with Simon on this:  There's
probably something screwy in your java code.

I'm assuming that your server waits to receive the word 'hello' before
replying with the three strings (first, second, and third)?  So once your
script sends the word 'hello', there's nothing for it to do but wait for a
response.   And that's exactly what your script does.





More information about the Python-list mailing list