Socket programming

A socket is an endpoint of a two-way communication system in a network. We create sockets so that we can send bits of information through them. To establish a Bluetooth communication between the devices, we need to create a socket. One socket will be on the server side and the other will be on the client side. In our case, the Android smartphone is the client and the RPi is the server.

The client socket tries to establish a connection with the server socket, while the server socket tries to listen to the incoming connection request from the client socket. In Bluetooth programming, we can choose between two socket options, RFCOMM and L2CAP, as represented in the following diagram:

In a socket program, the following connection ...

Get Hands-On Robotics Programming with C++ now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.