nodejs-multisock
NodeJS TCP and WebSocket Server Interface
Allows TCP and WebSockets to run simultaneously. Use net and WS.
Install
npm install node-multisock
Examples:
Initialize (INIT):
var Multisock = ;var ms = ;
Options
tcpPort
: (default: 8000) the TCP PortwsPort
: (default: 7000) the WebSocket PortmaxConnections
: (default: 0) Max Connections0
= unlimited
Get Started
var options = tcpPort: 70000 wsPort: 80000; var ms = options; ms; ms; ms;
Send:
ms.send(client, data)
Send a Message Note: Select TCP or WS automatic.
client
the Client Object.data
Sends data on the socket
ms;
Broadcast:
ms.broadcast(data, [ clients[] ])
Send to all Clients data.
data
Sends data on the socketclients[]
(optimal) list of clients
ms; // Send to all Clientsms;
Kick a client:
ms.kick(client)
Close a Connection.
client
the Client Object
ms;
Close
ms.close()
Close the Server.
Get Connections:
ms.getConnections()
Return Count of Clients.
var count = ms;console; // 0
Get Options:
ms.getOptions()
Returns the global Options.
var value = ms;console; /*{ tcpPort: 8000, wsPort: 7000, maxConnections: 0} */
Events
message
Fired when becomme a Message.
You will get the client
and the msg
as callback argument.
ms;
connect
Fired when a Client connect.
You will get the client
as callback argument.
ms;
disconnect
Fired when a Client disconnect.
You will get the client
as callback argument.
ms;
error
Fired when there was an error.
You will get the msg
as callback argument.
ms;
ToDo:
- Add more Tests
- Add all WS and NET Functions