-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsender.py
48 lines (37 loc) · 1.01 KB
/
sender.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# -*- coding: utf-8 -*-
"""
Created on Tue May 3 13:42:51 2022
@author: ACER
"""
# Sender
import socket
import cv2
import pickle
import struct
def get_ip_address():
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("8.8.8.8", 80))
return s.getsockname()[0]
# Socket creation
ser_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
host_ip = get_ip_address()
print(f"Server IP Address: {host_ip}")
port = 9999
socket_address = (host_ip, port)
ser_sock.bind(socket_address)
ser_sock.listen(5)
print(f"Server Serving at {ser_sock}")
while 1:
client, addr = ser_sock.accept()
print(f"Connected to Client@{addr}")
if client:
vid = cv2.VideoCapture(1)
while(vid.isOpened()):
img, frm = vid.read()
a = pickle.dumps(frm)
message = struct.pack("Q", len(a)) + a
client.sendall(message)
cv2.imshow('Sent Video', frm)
key = cv2.waitKey(1) & 0xff
if key == ord('q'):
client.close()