[Tutor] should we use multithreading for multiple clients in socket class
Surya K
suryak at live.com
Thu Apr 12 13:38:15 CEST 2012
I am learning networking and just wrote a primitive client server program..
server:
from time import ctimefrom socket import *
HOST = ""PORT = 21567BUFSIZ = 1024ADDR = (HOST, PORT)
tcpSerSoc = socket(AF_INET, SOCK_STREAM)tcpSerSoc.bind(ADDR)tcpSerSoc.listen(5)
while True: print "waiting for connection.." tcpCliSoc, addr = tcpSerSoc.accept() print "# Connected from:", addr while True: data = tcpCliSoc.recv(BUFSIZ) if not data: break tcpCliSoc.send( "[%s] %s" % (ctime(), data )) tcpCliSoc.clock()tcpSerSoc.close()
Client:
from socket import *
HOST = 'localhost'PORT = 21567BUFSIZ = 1024ADDR = (HOST, PORT)
tcpCliSoc = socket(AF_INET, SOCK_STREAM)tcpCliSoc.connect(ADDR)
while True: data = raw_input(">") if not data: break tcpCliSoc.send(data) data = tcpCliSoc.recv(BUFSIZ) if not data: break print datatcpCliSoc.close()
This client sends a string, and receives the same string with current time...
So, I tried to run another client (same code but from different file) but found that its now working.
why its happening, should I use multithreading so that I can handle two clients simultaneously??
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120412/713976d6/attachment.html>
More information about the Tutor
mailing list