title: Screen sharing in python
body: <p>Hi I'm stuck and I did not find anything helpful on the internet.
  I'm trying to make a screen-sharing program in python.
  The problem is that I can't send the screen in at least 24 fps, because when I take a screenshot with PIL (ImageGrab), something delays there.
  my client will get the picture (screenshot) from the server and "blit" it to 
  the screen using pygame. </p>
  
  <p>Server:</p>
  
  <pre><code># -*- coding: utf-8 -*-
  
  
  import socket
  import os
  import threading
  from PIL import ImageGrab
  def RetrFile(name, sock):
  
      while 1:
          img = ImageGrab.grab()
          img.save("PATH_TO_PIC")
  
          filename = "PATH_TO_PIC"
          sock.send(str(os.path.getsize(filename)))
          with open('PATH_TO_PIC', 'rb') as f:
              bytesToSend = f.read(1024)
              sock.send(bytesToSend)
              while bytesToSend != "":
                  bytesToSend = f.read(1024)
                  sock.send(bytesToSend)
  
  def Main():
     host = '0.0.0.0'
     port = 5000
  
     s = socket.socket()
     s.bind((host,port))
  
     s.listen(5)
     print "Server Started."
  
     while True:
         c, addr = s.accept()
         print "Client connected ip: &lt;"+ str(addr) + "&gt;"
         t = threading.Thread(target = RetrFile, args = ("retrThread", c))
         t.start()
     s.close()
  
  if __name__ == '__main__':
      Main()
  </code></pre>
  
  <p>Client:</p>
  
  <pre><code>import socket
  import pygame as pg
  def Main():
      host = '127.0.0.1'
      port = 5000
  
  
      pg.init()
      display_screen = pg.display.set_mode((1900, 1000))
  
  
  
      clock = pg.time.Clock()
  
      s = socket.socket()
      s.connect((host,port))
      filename =  "PATH_TO_PIC"
      isExit = False
      while not isExit:
  
          for event in pg.event.get():
              if event.type == pg.QUIT:
                  isExit = True
          data = s.recv(1024)
          print data
          filesize = long(data)
  
          f = open(filename, 'wb')
          data = s.recv(1024)
          totalRecv  =  len(data)
          f.write(data)
          while totalRecv &lt; filesize:
              data = s.recv(1024)
              totalRecv += len(data)
              f.write(data)
          showImg = pg.image.load('PATH_TO_PIC')
          display_screen.blit(showImg, (0,0))
          pg.display.flip()
          clock.tick(60)
      s.close()
  
  if __name__ == '__main__':
      Main()
  </code></pre>
  
  <p>Basically my question is: how to share a screen between 2 computers, I don't know if the way of sending a lot of pictures using PIL is efficient and right.
  is there a more efficient way? that casts the screen of computer no.1 and shows it at computer no.2 ?</p>