M
mukesh tiwari
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.
Thank you
Mukesh Tiwari
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/user/Programs/Mukesh_Tiwari/
python/tmp_1/screenshot.png',"png")
f=open('/home/user/Programs/Mukesh_Tiwari/python/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()
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
"client.py" 25L,
715C
7,2-9 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.
Thank you
Mukesh Tiwari
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/user/Programs/Mukesh_Tiwari/
python/tmp_1/screenshot.png',"png")
f=open('/home/user/Programs/Mukesh_Tiwari/python/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()
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
"client.py" 25L,
715C
7,2-9 All