newbie: write content in a file (server-side)

Thomas Kaufmann tokauf at googlemail.com
Sun Jul 29 10:16:01 EDT 2012


Hi,

I send from a client file content to my server (as bytes). So far so good.
The server receives this content complete. Ok. Then I want to write this content to a new file. It works too. But in the new file are only the first part of the whole content.

What's the problem. 

o-o

Thomas

Here's 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")
                print(s)
                li = s.split("~")
                with open(li[0], 'w') as fp:
                    fp.write(li[1])        
                
#... main ......................................................
                
if __name__ == "__main__":

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



More information about the Python-list mailing list