SocketServer and a Java applet listener
google at phaedro.com
google at phaedro.com
Wed Aug 24 15:59:52 EDT 2005
Dear newsgroup,
I give up, I must be overseeing something terribly trivial, but I can't
get a simple (Java) applet to react to incoming (python) SocketServer
messages.
Without boring you with the details of my code (on request available,
though), here is what I do :
I have a TCPServer and BaseRequestHandler .
Connecting via telnet : everything goes OK.
Connecting from Applet :
problem 1 (worked around it) : java has some 'propietary' UTF-8 format,
python's unicode doesn't seem to handle it correctly and I have to
strip the first two bytes/chars , then all goes OK .
problem 2:
I have tried IMHO everything.
In the BaseRequestHandler.handle() method, I want to update a list of
clients in the server, i.e.:
self.server.players[username] = self
self := instance of the BaseRequestHandler, I only do this after
succesfull connect , i.e. first time socket. I assume (wrongfully?)
that I can now use the self.request socket for future transmissions to
the client.
In the applet, I start a thread that listens to the socket by eternally
looping over:
String line = self.din.readUTF()
if (line == null)
break;
handle(line);
self := instance of Thread
self.din := DataInputStream(socket.getInputStream());
(It's a bit simplistic, but I am quite sure (well...) I got those
things right, the issue seems to me to lie in some weird
java-python-socket anomaly having to do with close()/flush() etc. ...)
However, the handle(line) method only seems to get called when I
destroy (close ?) the socket on the server side. I tried making it a
wfile (socket.makefile) and calling the flush() method.
Moreover, I searched and googled and couldn't find reference to a
working implementation of a python SocketServer sending to a java
Applet (socket listener).
Would be much appreciated if anyone knows such a reference ?
Any pointers to correct handling of the 'java propietary UTF-8 format'
in python (xml.sax) would also be appreciated. Skipping the first two
bytes really is a smelly workaround, I know, *deep sigh*...
--
Thijs Cobben
www.phaedro.com
More information about the Python-list
mailing list