Bi-Directional Client
Problem
You want to a persistent service over a network, one which maintains an on-going connection with its clients.
Solution
Create a bi-directional TCP client.
In Node.js
Example Usage
Accessing the Bi-Directional Server:
Discussion
This particular example initiates contact with the server and starts the conversation in the @connection.on ‘connect’@ handler. The bulk of the work in a real client, however, will lie in the @connection.on ‘data’@ handler, which processes output from the server. The @ping@ function only recurses in order to illustrate continuous communication with the server and can be removed from a real client.
See also the Bi-Directional Server, Basic Client, and Basic Server recipes.
Exercises
- Add support for choosing the target domain and port based on command-line arguments or from a configuration file.