9 Connecting to Pedro

The communication between each client and the Pedro server is via a pair of sockets. One is used for two-way data transfer (e.g. notifications, subscriptions), the other is used for the server to acknowledge messages from the client. This will be a 0 for invalid data from the client and non-zero for valid data.

The creation of the two sockets is done as follows. Examples are given in the code for the Python and Java APIs.

  1. Create a socket in the client (this will be used to obtain information from the server)
  2. Use connect to connect the socket to the Pedro server. Pedro will be listening for the connection on a given port. The default port is 4550.
  3. Read an IP address and two ports (sent by the server as a newline terminated string). The IP address is to be used for the connection to the server. The two ports are for connecting two sockets (for acknowledgements and for data).
  4. Close the socket.
  5. Create a socket in the client (this will be used for acknowledgements).
  6. Use connect to connect the socket to the Pedro server for acknowledgements. Pedro will be listening for the connection on the first of the two ports send by the server.
  7. Read the client ID on this socket (sent by the server as a newline terminated string).
  8. Create another socket in the client (this will be used for data).
  9. Use connect to connect the socket to the Pedro server for data. Pedro will be listening for the connection on the second of the two ports send by the server.
  10. Send the client the client ID on the data socket (the same string the server sent above).
  11. Read the status on the data socket. If the connection succeeds the status will be the string "ok\n".