Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > newbie: write new file (from a server)

Reply
Thread Tools

newbie: write new file (from a server)

 
 
tokauf@googlemail.com
Guest
Posts: n/a
 
      07-29-2012
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Program to open a file in binary, skip X bytes and write the rest ofthe file to a new file scad C++ 4 05-28-2009 08:47 AM
When using System.IO.FileStream, I write 8 bytes, then seek to the start of the file, does the 8 bytes get flushed on seek and the buffer become a readbuffer at that point instead of being a write buffer? DR ASP .Net 2 07-29-2008 09:50 AM
When using System.IO.FileStream, I write 8 bytes, then seek to the start of the file, does the 8 bytes get flushed on seek and the buffer become a readbuffer at that point instead of being a write buffer? DR ASP .Net Building Controls 0 07-29-2008 01:37 AM
How to open a new console and write something out write printf() Peter Hansen C++ 1 08-24-2003 11:49 AM
How to open a new console and write something out write printf() Peter Hansen C Programming 1 08-24-2003 11:49 AM



Advertisments