read/write to java socket in python

Jean-Paul Calderone exarkun at divmod.com
Tue Nov 27 10:21:36 EST 2007


On Tue, 27 Nov 2007 07:08:04 -0800 (PST), madsornomads at gmail.com wrote:
>Hi all,
>
>I have a problem with reading from a Java server after I have written
>to it - it just hangs. It works fine if I just write to the server and
>not try to write. I have read the HOWTO on sockets - and it states
>that there is a problem (something about flushing), but not what the
>solutions is. Nor do google. Can somebody please help?
>
>A few lines down you can see the example code that sums up the
>problem. Just change the name of the Python HOST-variable.
>
>Thanks
>Mads
>
>
> [snip]
>s.send("Hi Java Server");

Here, you sent some bytes (maybe - you didn't check the return value of
send, so it's possible nothing at all was sent) but you didn't send a new
line indicator of any sort.

> [snip]
>                                                print(buf.readLine());

Here, you tried you read a line from the socket.  The peer never sent a
whole line though, so readLine will never succeed.

Jean-Paul



More information about the Python-list mailing list