Re: python server socket file transfer

2018-01-10 Thread bingbong3334
On Wednesday, January 10, 2018 at 9:07:33 AM UTC+2, dieter wrote:
> bingbong3...@gmail.com writes:
> > 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
> > ...
> > self.sock.send(l)
> 
> Please read the documentation for *send* in the "socket" module:
> it tells you that "send" (in contrast to "sendall") is *not* guarantied
> to send the complete *l* (there is no guarantee how much is sent);
> the return value of "send" tells you how many bytes have been sent.


bro i dont ask about if it works or not or what you say is not right i ask how 
much he can handel...
-- 
https://mail.python.org/mailman/listinfo/python-list


python server socket file transfer

2018-01-09 Thread bingbong3334
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(Thread):

def __init__(self,ip,port,sock):
Thread.__init__(self)
self.ip = ip
self.port = port
self.sock = sock
print " New thread started for "+ip+":"+str(port)

def run(self):
filename='System.exe'
f = open(filename,'rb')
while True:
l = f.read(BUFFER_SIZE)
while (l):
self.sock.send(l)
#print('Sent ',repr(l))
l = f.read(BUFFER_SIZE)
if not l:
f.close()
self.sock.close()
break

tcpsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
tcpsock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
tcpsock.bind((TCP_IP, TCP_PORT))
threads = []

while True:
tcpsock.listen(1)
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(socket.AF_INET, socket.SOCK_STREAM)
s.connect((TCP_IP, TCP_PORT))
with open('Sys.exe', 'wb') as f:
print 'file opened'
while True:
#print('receiving data...')
data = s.recv(BUFFER_SIZE)
if not data:
f.close()
print 'file close()'
break
# write data to a file
f.write(data)
except:
print "problem"

print('Successfully get the file')
s.close()
print('connection closed')
-- 
https://mail.python.org/mailman/listinfo/python-list