SockerServer.TCPServer problem

huy nytimes at swiftdsl.com.au
Tue Aug 17 16:23:46 CEST 2004


Hi All,

Can someone explain why this bit of code can't keep up with some java 
code which spawns about 200 (threads) simultaneous connections each 
sending about 10 mesgs each. I basically don't get the 2000 connections 
i expect on the python side. I end up with some number very close on 
different runs eg. 1989, 1972, 1992 etc.

Any ideas ?

Huy

#!/usr/local/bin/python

import socket
import struct
import time
import SocketServer
import thread
from datetime import datetime

import os
import datetime
import random

LISTENING_PORT = 1600

cnt = 0

class PDAHandler(SocketServer.BaseRequestHandler):
    def handle(self):
       global cnt

       cnt += 1
       s = self.request
       dlen = s.recv(4, socket.MSG_WAITALL)
       print "Received: ", dlen, cnt, " from ", s.getpeername()
       dataLen = struct.unpack("!i", dlen)
       data = s.recv(dataLen[0])
       f = file("aaa/recv%02d.txt" % cnt, "w+")
       f.write(data)
       f.close()


def start_servers():
    msg_server = SocketServer.TCPServer(("", LISTENING_PORT), PDAHandler)
    msg_server.serve_forever()

if __name__ == "__main__":
    start_servers()



More information about the Python-list mailing list