Download Lessons Learned Constructing the NG-Mesh Wireless

Transcript
3.3. The Socket Programs
3.3.3
McMaster - Elec. Eng. - M.A.Sc. - S.W.K. Ng
The UDP Server
The complete source code for the UDP server program is shown in Figure 3.38 to Figure 3.41. On the server-side, the routing of packets is configured to force all received
data to enter only through the hard-coded Wi-Fi interface with the familiar call to
the SO BINDTODEVICE socket option. In contrast to the client-side application,
the server binds the server IP address and port to the socket in order to instruct the
server interface, which is also bound to the socket, to accept only the packets that
have a destination address and port that matches the ones specified and bound to
that interface.
Being at the receiving end of the communication stream, the file descriptor settings
mirror the ones found at the client-side of the socket. Thus, on the server-side, data
is read from the socket and written to the specified location on the local hard disk.
Similar to the capturing of starting and ending time-stamps during transmission on
the client endpoint, the starting and ending time-stamps for data reception is also
captured on the server-side.
In order to compliment the order of items sent by the client application, the server
must listen for the client-sent items in the client-sent order. Namely, file size comes
first, followed by filename, and finally the file data is expected last.
55