how much client can i handel whit this code what the amount of client that i can handel
the size of the file is 716 kb
import socket
from threading import Thread
from SocketServer import ThreadingMixIn
##
TCP_IP = ''
TCP_PORT = 3156
BUFFER_SIZE = 1024
class ClientThread(Th read):
def __init__(self,i p,port,sock):
Thread.__init__ (self)
self.ip = ip
self.port = port
self.sock = sock
print " New thread started for "+ip+":"+str(po rt)
def run(self):
filename='Syste m.exe'
f = open(filename,' rb')
while True:
l = f.read(BUFFER_S IZE)
while (l):
self.sock.send( l)
#print('Sent ',repr(l))
l = f.read(BUFFER_S IZE)
if not l:
f.close()
self.sock.close ()
break
tcpsock = socket.socket(s ocket.AF_INET, socket.SOCK_STR EAM)
tcpsock.setsock opt(socket.SOL_ SOCKET, socket.SO_REUSE ADDR, 1)
tcpsock.bind((T CP_IP, TCP_PORT))
threads = []
while True:
tcpsock.listen( 10000)
print "Waiting for incoming connections..."
(conn, (ip,port)) = tcpsock.accept( )
print 'Got connection from ', (ip,port)
newthread = ClientThread(ip ,port,conn)
newthread.start ()
threads.append( newthread)
for t in threads:
t.join()
and the client side is
import socket
TCP_IP = ''
TCP_PORT = 3156
BUFFER_SIZE = 1024
try:
s = socket.socket(s ocket.AF_INET, socket.SOCK_STR EAM)
s.connect((TCP_ IP, TCP_PORT))
with open('Sys.exe', 'wb') as f:
print 'file opened'
while True:
#print('receivi ng data...')
data = s.recv(BUFFER_S IZE)
if not data:
f.close()
print 'file close()'
break
# write data to a file
f.write(data)
except:
print "problem"
print('Successf ully get the file')
s.close()
print('connecti on closed')
the size of the file is 716 kb
import socket
from threading import Thread
from SocketServer import ThreadingMixIn
##
TCP_IP = ''
TCP_PORT = 3156
BUFFER_SIZE = 1024
class ClientThread(Th read):
def __init__(self,i p,port,sock):
Thread.__init__ (self)
self.ip = ip
self.port = port
self.sock = sock
print " New thread started for "+ip+":"+str(po rt)
def run(self):
filename='Syste m.exe'
f = open(filename,' rb')
while True:
l = f.read(BUFFER_S IZE)
while (l):
self.sock.send( l)
#print('Sent ',repr(l))
l = f.read(BUFFER_S IZE)
if not l:
f.close()
self.sock.close ()
break
tcpsock = socket.socket(s ocket.AF_INET, socket.SOCK_STR EAM)
tcpsock.setsock opt(socket.SOL_ SOCKET, socket.SO_REUSE ADDR, 1)
tcpsock.bind((T CP_IP, TCP_PORT))
threads = []
while True:
tcpsock.listen( 10000)
print "Waiting for incoming connections..."
(conn, (ip,port)) = tcpsock.accept( )
print 'Got connection from ', (ip,port)
newthread = ClientThread(ip ,port,conn)
newthread.start ()
threads.append( newthread)
for t in threads:
t.join()
and the client side is
import socket
TCP_IP = ''
TCP_PORT = 3156
BUFFER_SIZE = 1024
try:
s = socket.socket(s ocket.AF_INET, socket.SOCK_STR EAM)
s.connect((TCP_ IP, TCP_PORT))
with open('Sys.exe', 'wb') as f:
print 'file opened'
while True:
#print('receivi ng data...')
data = s.recv(BUFFER_S IZE)
if not data:
f.close()
print 'file close()'
break
# write data to a file
f.write(data)
except:
print "problem"
print('Successf ully get the file')
s.close()
print('connecti on closed')