newbie: write content in a file (server-side)
Thomas Kaufmann
tokauf at googlemail.com
Mon Jul 30 05:51:18 EDT 2012
Am Sonntag, 29. Juli 2012 16:16:01 UTC+2 schrieb Thomas Kaufmann:
> 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()
Thanks a lot. It helps.
More information about the Python-list
mailing list