reading from sockets

Simon Forman rogue_pedro at yahoo.com
Sat Aug 12 13:41:11 EDT 2006


AndrewTK wrote:
> > 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
>
> Nope - actually it's a threaded "server", with the main thread simply
> dumping network input to the console and command line input being
> directly dumped to the network output stream.
>
> I confess to having typed the three lines manually...!
>
> It's at:
> http://www.dcs.st-and.ac.uk/~atk1/perso/java/servers/RespondingServer.java
>
> It launches on the command line with
> java RespondingServer _port_
>
> _port_ being the port number it should listen for data on.

Hooooy.  I tried reading your Java code..  What can I say?  There's a
reason why I like Python...  :-)

I couldn't see anything obviously broken in your server, but there's
definitely nothing wrong with your python code, except that you call
flush() on the socket (fixed in your posted code but not in the linked
code.)

Here are the results of testing, with netcat substituted for your java
server:

# on the server side:
sforman at garbage:~ $ netcat -p 54321 -l
hellohi there
how are you
I'm fine thanks

sforman at garbage:~ $



# on the client side:
sforman at garbage:~ $ python delme.py
'hi there\n'
'how are you\n'
"I'm fine thanks\n"
sforman at garbage:~ $


So I'm guessing it's something wrong in your java server.

HTH,
~Simon




More information about the Python-list mailing list