#server code
import socket, cv2, pickle,struct,imutils

# Socket Create
server_socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)

# host_ip = '169.254.250.37'
host_name  = socket.gethostname()
host_ip = socket.gethostbyname(host_name)
print('HOST IP:',host_ip)
port = 9999
socket_address = (host_ip,port)

# Socket Bind
server_socket.bind(socket_address)

# Socket Listen
server_socket.listen(5)
print("LISTENING AT:",socket_address)

# Socket Accept

while True:
    client_socket,addr = server_socket.accept()
    print('Connection From:',addr)
    if client_socket:
        vid = cv2.VideoCapture(0)

    while(vid.isOpened()):
        img,frame = vid.read()
        frame = imutils.resize(frame,width=320)
        a = pickle.dumps(frame)
        message = struct.pack("Q",len(a))+a
        client_socket.sendall(message)

        cv2.imshow('Video Being Transmitted',frame)
        key = cv2.waitKey(1) & 0xFF
        if key ==ord('q'):
            client_socket.close()
            
#client_socket.close()
#server code
import socket, cv2, pickle,struct,imutils

# Socket Create
server_socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)

# host_ip = '169.254.250.37'
host_name  = socket.gethostname()
host_ip = socket.gethostbyname(host_name)
print('HOST IP:',host_ip)
port = 9999
socket_address = (host_ip,port)

# Socket Bind
server_socket.bind(socket_address)

# Socket Listen
server_socket.listen(5)
print("LISTENING AT:",socket_address)

# Socket Accept

while True:
    client_socket,addr = server_socket.accept()
    print('Connection From:',addr)
    if client_socket:
        vid = cv2.VideoCapture(0)

    while(vid.isOpened()):
        img,frame = vid.read()
        frame = imutils.resize(frame,width=320)
        a = pickle.dumps(frame)
        message = struct.pack("Q",len(a))+a
        client_socket.sendall(message)

        cv2.imshow('Video Being Transmitted',frame)
        key = cv2.waitKey(1) & 0xFF
        if key ==ord('q'):
            client_socket.close()
            
#client_socket.close()
#server code # Socket Create # host_ip = '169.254.250.37' # Socket Bind # Socket Listen # Socket Accept #client_socket.close()