title: OpenCV live stream video over socket in Python 3
body: <p>I am trying to create a simple application to send live stream video over the socket in Python 3 with OpenCV. I am new to OpenCV and socket programming so if you can provide answer in detail I will be very grateful. Thank you.</p>
  
  <p>Here is sender.py</p>
  
  <pre><code>import socket
  import time
  
  import cv2
  
  capture = cv2.VideoCapture(0)
  sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  sock.connect(('192.168.1.10', 50505))
  
  while True:
      ret, frame = capture.read()
      data = cv2.imencode('.jpg', frame)[1].tostring()
      sock.sendall(data)
      time.sleep(2)
  </code></pre>
  
  <p>Here is receiver.py</p>
  
  <pre><code>import socket
  import cv2
  import numpy as np
  import time
  
  HOST = '192.168.1.10'
  PORT = 50505
  
  s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  print('Socket created')
  
  s.bind((HOST, PORT))
  print('Socket bind complete')
  
  s.listen(10)
  print('Socket now listening')
  
  conn, addr = s.accept()
  
  while True:
      data = conn.recv(8192)
      nparr = np.fromstring(data, np.uint8)
      frame = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
      cv2.imshow('frame', frame)
      time.sleep(2)
  </code></pre>
  
  <p>and this is the error   </p>
  
  <pre><code> receiver.py", line 29, in &lt;module&gt;
          cv2.imshow('frame', frame)
      cv2.error: D:\Build\OpenCV\opencv-3.4.0\modules\highgui\src\window.cpp:339:
  error: (-215) size.width&gt;0 &amp;&amp; size.height&gt;0 in function cv::imshow
  </code></pre>