-
Notifications
You must be signed in to change notification settings - Fork 0
/
B.py
58 lines (51 loc) · 1.48 KB
/
B.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
49
50
51
52
53
54
55
56
57
58
import socket
import threading
import cv2
import numpy
from io import BytesIO
######## server B #########
server=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind(("127.0.0.1",2324))
server.listen()
ip=input('Enter Friend\'s IP: ')
port=int(input('Enter Friend\'s Port Number: '))
######## client for A ########
remoteserver=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
remoteserver.connect((ip,port))
####### receiving data from client A #######
def receive():
client,address=server.accept() #### accept connections ####
while True:
np_bytes = client.recv(1000000) #### 10lac bytes data received ####
if not np_bytes:
break
load_bytes = BytesIO(np_bytes)
try:
photo_recv = numpy.load(load_bytes)
except:
pass
cv2.imshow("ClientA", photo_recv)
cv2.waitKey(1)
if cv2.waitKey(10)==13:
break
cv2.destroyAllWindows()
client.close()
######## sending data to server B #######
def send():
cap=cv2.VideoCapture(1)
while True:
try:
ret,photo=cap.read()
np_bytes = BytesIO()
numpy.save(np_bytes, photo)
np_bytes = np_bytes.getvalue()
remoteserver.send(np_bytes)
except:
cap.release()
break
######## Creating Threads #######R
T1=threading.Thread(target=send)
T2=threading.Thread(target=receive)
######## Starting Threads #######
T1.start()
T2.start()