![Freenove Raspberry Pi 2 Model B Manual Download Page 99](http://html.mh-extra.com/html/freenove/raspberry-pi-2-model-b/raspberry-pi-2-model-b_manual_2330437099.webp)
Need support?
97
Chapter 4 Robot Dog
█
www.freenove.com
Client
The client can receive video data and commands from the server, and can send commands to the server. And
it can run on different systems, such as windows, macOS and so on. However, you need to install related
software and libraries when running it.
Part of client code is as below:
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
def
turn_on_client
(self,ip):
self
.client_socket1 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self
.client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
(ip)
def
turn_off_client
(self):
try
:
self
.client_socket.shutdown(2)
self
.client_socket1.shutdown(2)
self
.client_socket.close()
self
.client_socket1.close()
except
Exception
as
e:
(e)
def
receiving_video
(self,ip):
stream_bytes = b
' '
try
:
self
.client_socket.connect((ip, 8000))
self
.connection =
self
.client_socket.makefile(
'rb'
)
except
:
#print ("command port connect failed")
pass
while
True
:
try
:
stream_bytes=
self
.connection.read(4)
leng=struct.unpack(
'L'
, stream_bytes[:4])
jpg=
self
.connection.read(leng[0])
if
self
.is_valid_image_4_bytes(jpg):
if
self
.video_flag:
self
.image = cv2.imdecode(np.frombuffer(jpg, dtype=np.uint8),
cv2.IMREAD_COLOR)
if
self
.ball_flag:
self
.Looking_for_the_ball()
self
.video_flag=
False
except
BaseException
as
e:
(e)
break
Summary of Contents for Raspberry Pi 2 Model B
Page 35: ...Need support support freenove com 33 Chapter 0 Raspberry Pi Preparation www freenove com ...
Page 71: ...Need support support freenove com 69 Chapter 2 Assemble Robot www freenove com M3 Nut M3x12 ...
Page 98: ...Need support support freenove com 96 Chapter 4 Robot Dog www freenove com ...