sending more then 2 messages at a time to a SocketServer fails
Tamer Higazi
th982a at googlemail.com
Tue Nov 1 15:12:46 EDT 2011
Am 01.11.2011 17:13, schrieb Miki Tebeka:
> MKTest.getObj(data[0]) will return the same object on every call(with the same data that was initialized 1'st time). Any Daten parameter after the 1'st call is ignored.
Not true!
The singleton object has nothing todo. Here one more example for you:
Client:
import socket
data = ['Tamer']
received = [None,None]
HOST,PORT = "localhost",9999
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((HOST, PORT))
sock.send('%s' % data)
received[0] = sock.recv(1024)
sock.send('%s' % data)
received[1] = sock.recv(1024)
sock.close()
print received
Server:
import SocketServer
from ast import literal_eval
class MySockX(SocketServer.BaseRequestHandler):
def handle(self):
data = self.request.recv(1024)
data = literal_eval(data)
data = '%s' % data[0]
self.request.send('%s %s' % ('Halloaaa',data))
if __name__ == "__main__":
HOST, PORT = "localhost", 9999
server = SocketServer.TCPServer((HOST,PORT),MySockX)
server.serve_forever()
with it's result:
['Halloaaa Tamer', '']
the 2nd argument from the list is EMPTY. Now tell me why?!
More information about the Python-list
mailing list