A very simple high-level JSON-based messaging socket server and client.
Usage
server:
var port = 9000;var server = replier;
client:
var client = replier; // the result is 6
replier.check(port, callback)
Checks if there's already a server listening to the given port
.
- port
Number
- callback(alive)
Function
- alive
Boolean
true, if the server is alive.
- alive
replier.server()
Creates and returns a replier server object which is an instance of replier.Server
.
replier;
The code above is relevant to:
replier;
Class: replier.Server
server.listen(port, [callback]);
Listens to a port.
Event: 'message'
Emitted when the server has reseived a message from the client.
Differs from normal events, this event passes a function reply
parameter which is used to reply responses to the client.
- message
mixed
- reply
function(err, response)
err
andresponse
will be passed to thecallback
ofclient.send(message, callback)
Event: 'listening'
Emitted when the server has been bound after calling server.listen.
Event: 'close'
Emitted when the server closes. Note that if connections exist, this event is not emitted until all connections are ended.
Event: 'error'
Error Object
Emitted when an error occurs. The 'close' event will be called directly following this event. See example in discussion of server.listen.
replier.client([options])
Class: replier.Client([options])
- options
Object
The options ofnet.Socket
client.connect(port, callback)
- port
Number
- callback(err)
Function
- err
Error Object
server error, see The GNU C Library - Error Reporting for details
- err
Connects the client to the server.
client.send(data, callback)
- data
Object
The data to be sent to the server - callback(err, serverData)
- err
mixed
error information from the server - serverData
mixed
server data
- err
Sends messages to the server, and
client.end()
Close the client.
Events
Events of net.Socket
'connect'
'error'
'end'
'data'
'timeout'
'close'
'drain'