Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Python

newbie: write new file (from a server)



Python python RSS feed   Index | Next | Previous | View Threaded

tokauf at googlemail

Jul 29, 2012, 7:04 AM

Post #1 of 1 (236 views)
newbie: write new file (from a server)


I have a client. He sends file content (as bytes) to my server. The server receives this content as bytes and decodes it to string. Then the server opens a file (filename comes from client) try to write the file-content to the new file.
It works but there are parts of the client file content in the new file.

I tested it: the whole content from client comes to the server.

Can anybody help me?

My server code:


import socketserver

class MyTCPServer(socketserver.BaseRequestHandler):

def handle(self):

s = ''
li = []
addr = self.client_address[0]
print("[{}] Connected! ".format(addr))
while True:

bytes = self.request.recv(4096)
if bytes:
s = bytes.decode("utf8")
li = s.split("~")
with open(li[0], 'w') as fp:

#... main ......................................................

if __name__ == "__main__":

server = socketserver.ThreadingTCPServer(("", 12345), MyTCPServer)




Python python RSS feed   Index | Next | Previous | View Threaded

Interested in having your list archived? Contact Gossamer Threads
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.