Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #26186 > unrolled thread
| Started by | tokauf@googlemail.com |
|---|---|
| First post | 2012-07-29 07:04 -0700 |
| Last post | 2012-07-29 07:04 -0700 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
newbie: write new file (from a server) tokauf@googlemail.com - 2012-07-29 07:04 -0700
| From | tokauf@googlemail.com |
|---|---|
| Date | 2012-07-29 07:04 -0700 |
| Subject | newbie: write new file (from a server) |
| Message-ID | <fa851b00-ba10-45e6-aeb4-e115df919fb1@googlegroups.com> |
Hi,
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")
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()
--------------------------------
o-o
Thomas
Back to top | Article view | comp.lang.python
csiph-web