Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #26188

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

From Thomas Kaufmann <tokauf@googlemail.com>
Newsgroups comp.lang.python
Subject newbie: write content in a file (server-side)
Date 2012-07-29 07:16 -0700
Organization http://groups.google.com
Message-ID <98f9b4a6-b797-40f3-a919-89c2d4fb4496@googlegroups.com> (permalink)

Show all headers | View raw


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()

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

newbie: write content in a file (server-side) Thomas Kaufmann <tokauf@googlemail.com> - 2012-07-29 07:16 -0700
  Re: newbie: write content in a file (server-side) Peter Otten <__peter__@web.de> - 2012-07-29 17:16 +0200
    Re: newbie: write content in a file (server-side) Thomas Kaufmann <tokauf@googlemail.com> - 2012-07-30 02:50 -0700
    Re: newbie: write content in a file (server-side) Thomas Kaufmann <tokauf@googlemail.com> - 2012-07-30 02:50 -0700
  Re: newbie: write content in a file (server-side) Thomas Kaufmann <tokauf@googlemail.com> - 2012-07-30 02:51 -0700

csiph-web