473,395 Members | 1,521 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

python server socket file transfer

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(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(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')
Jan 9 '18 #1
0 2493

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Philipp Brune | last post by:
Hi all, the following problem occured to me and I hope somebody can help me : I need to implement an encrypted File download with a PHP script on the server side and a c# client application....
1
by: ADE | last post by:
Hi everyone well from my last post I found what I am looking for I have some code now that transfers files I have added a GUI to it and need some help with two things one my loadtemplate()...
3
by: Papanii | last post by:
Hi Guys, I am a newbie to the whole dot net framework and need a few pointers. I want to create an file transfer program (i.e form PC to PC) but i don't know where to start. Can anyone point me...
3
by: Alessandro | last post by:
Hi all! I'm trying to write a file transfer application using TCP, but I'm having some problem to connect the client and the server. Sniffing with Ethereal I can see the packets sent from the...
10
by: David | last post by:
I have googled to no avail on getting specifically what I'm looking for. I have found plenty of full blown apps that implement some type of file transfer but what I'm specifcally looking for is an...
5
by: raghubr | last post by:
Hi all, Can any one pls guide me through..I need to transfer the file from server to client and client to server using sockets in an Asynchronous mode so this file transfer doesn't hinder the...
3
by: spasavvas | last post by:
Hi I am trying to create a server – client model where client send a file and when server receive the file send back an ack msg. My code is: import java.net.*; import java.io.*; class...
1
by: Saurabh | last post by:
Dear All, Can anyone tell me, how to write such a program that can transfer files (either binary or text) behind NAT devices( such as for computers behind firewalls and routers and other NAT...
14
by: Bapes | last post by:
Hello, I am currently trying to create a server/client file transfer system in which the server sends the client .mp3 files. The file transfers fine but when I go to play the file, it is all scratchy...
2
by: kashifjawed | last post by:
I'm developing a c# asynchronous socket application for tranfering file or large data from client to server and server to client as well in chunks. Application sometimes transfer file from client...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.