Re: File transfer on network



mukesh tiwari wrote:
Hello all
Currently i am trying to develop a client and server in python. Client
takes screenshot in every 20 seconds and send it to server. Server
store the received file in folder. Here is code for Client

import sys
import socket
import gtk.gdk
import time
if __name__ == "__main__":
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);
host,port="localhost",50007
s.connect((host,port))
while 1:
w = gtk.gdk.get_default_root_window()
sz = w.get_size()
pb = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB,False,8,sz[0],sz[1])
pb = pb.get_from_drawable(w,w.get_colormap(),0,0,0,0,sz[0],sz[1])
if (pb != None):
pb.save('/home/tmp_1/screenshot.png',"png")
f=open('/home//tmp_1/screenshot.png','rb')
while 1:
blk=f.read(2048)
if not blk:break
s.send(blk)
f.close()
print 'file transfer done';
time.sleep(20)

s.close()


Server Code
import sys
import socket
import time
if __name__ == "__main__":

s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
host,port="",50007
s.bind((host,port))
s.listen(1)
conn,add=s.accept()
i=0
while 1:
f=open('/home/tmp_2/copyscreenshot_'+str(i)+'.png','wb')
while 1:
data=conn.recv(2048)
if not data:break
f.write(data)

f.close()
print 'file received'
time.sleep(20)
i+=1;
#print ' file received '

conn.close()


My problem is that server is copying only first image
copyscreenshot_0.png while my client continuously taking screen shot.
Kindly tell me what is wrong with my server code.

The .recv will return an empty string only when the connection is closed
by the client, but the client keeps the connection open.

You could either open and close a connection for each image, or have the
client tell the server how many bytes it's going to send, followed by
the bytes (my preference would be to send the size as a string ending
with, say, a newline).

Another point: the .send method doesn't guarantee that it'll send all
the bytes (it'll return the number of bytes that it has actually sent);
use the .sendall method instead.
.



Relevant Pages

  • Re: .Net Scalability problem
    ... LoadRunner will peak out a server with a few virtual users. ... To get an idea of load, ... Fire off the test client and watch the number of ... > So I think that the MTC generate concurrent connection and per ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Connection lost at same time every hour (sometimes)
    ... After making the two following alterations on the server the problem seems ... After analyze your ipconfig on SBS and client, ... Then, other connection is good, ...
    (microsoft.public.windows.server.sbs)
  • Re: server disconnection - very often
    ... Reason of permanent popups is VMware server aplication on clients. ... Run CEICW to configure the network of SBS: ... Two network adapters - manual router connection to broadband ... Uninstall VMware on client. ...
    (microsoft.public.windows.server.sbs)
  • Re: Lan setup 2 nic
    ... The external nic only has TCP/IP enabled. ... Ipconfig of the server is looking good, but the client is still missing the ... > connection so we have a 2 nic with router setup now. ...
    (microsoft.public.windows.server.sbs)
  • Re: Regular disconnections from remote web workplace
    ... I can connect to office server and all office clients from home at all times ... be physically working right up until the connection is lost. ... If I enter http://companyip from a client I receive the login screen for the ... Click Services tab and select Hide All Microsoft Services and Disable ...
    (microsoft.public.windows.server.sbs)