read/write to java socket in python

madsornomads at gmail.com madsornomads at gmail.com
Tue Nov 27 19:30:16 CET 2007


On Nov 27, 4:21 pm, Jean-Paul Calderone <exar... at divmod.com> wrote:
> On Tue, 27 Nov 2007 07:08:04 -0800 (PST), madsornom... 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

Thanks, sometimes the obvious causes the biggest problems ;) Thanks a
lot!

/Mads



More information about the Python-list mailing list