
60
datasheet
contains some PDF files about the chip (you need to view them on PC),
mjpg-streamer
, the camera driver to acquire and upload images
server
, the server run on the Raspberry Pi
Introduction of Socket
The C/S-structure program of the SunFounder Raspberry Pi-based Smart Car is
written based on the socket module of the Python language. Socket wraps and
applies the TCP/IP and is used to describe IP address and port. Also it is a network
data structure for computer. The socket module should be created before the
communication of network applications. If the socket can be said to be the plug of
a telephone, which is the lowest layer of communication, then the combination of IP
address and ports can be said to be that of area code and phone numbers. Only
having the hardware for a phone call making is not enough. You still need to know
whom and where to call. An Internet address is composed of the essential IP
address and port for network communication.
1.
Server
Here we provide a pseudocode which creates a universal TCP server for explanation.
Note that this is just one of the methods for server design. After you have a good
knowledge about it, you can alter the pseudocode as you want:
s
=
socket
( )
# Create a socket for the server.
s
.
bind
( )
# Bind the address to the socket.
s
.
listen
( )
# Listen to the connection.
inf_loop
:
# Indefinite loop of the server.
c
=
s
.
accept
( )
# Accept the connection from the client.
comm_loop
:
# Communication loop.
c
.
recv
( )/
c
.
send
( )
# Dialog (receiving or sending
data)
c
.
close
( )
# Close the socket of the client.
s
.
close
( )
# Close the socket of the server (optional).
All kinds of socket can be created via the function
socket.socket( )
and then bound
with IP address and port by the function
bind( )
. Since TCP is a connection-oriented
communication system, some settings need to be completed before the TCP server
starts operation. The TCP server must "listen" to connections from the client.
After the settings are done, the server will enter an indefinite loop. A simple, like
single-thread, server will call the function
accept( )
to wait for the coming
connection. By default, the function
accept( )
is a blocking one, which means it is
suspended before the connection comes. Once a connection is received, the
function
accept( )
returns a separate client socket for the subsequent
communication. After the temporary socket is created, communication begins.
Both the server and client use the new socket for data sending and receiving. The
Содержание Smart Video Car Kit
Страница 4: ...2 Components i Acrylic Plates ...
Страница 40: ...38 The whole picture of wiring should be like this ...
Страница 42: ...40 Now the circuit is completed Congratulations The car should be assembled successfully as shown below ...
Страница 65: ...63 Process Diagram of Client Program ...