Bi-Directional Server
Problem
You want to provide a persistent service over a network, one which maintains an on-going connection with a client.
Solution
Create a bi-directional TCP server.
In Node.js
Example Usage
Accessed by the Bi-Directional Client:
Discussion
The bulk of the work lies in the @socket.on ‘data’@ handler, which processes all of the input from the client. A real server would likely pass the data onto another function to process it and generate any responses so that the original handler.
See also the Bi-Directional Client, Basic Client, and Basic Server recipes.
Exercises
- Add support for choosing the target domain and port based on command-line arguments or on a configuration file.