McBain-WithWebSocket

 view release on metacpan or  search on metacpan

examples/client.js  view on Meta::CPAN

 * To use this client, run `node client.js 8080` (change to the port where
 * your server is running). You can then issue requests to the API by
 * printing lines into the console, in the format "key1=value1 key2=value2",
 * which will be automatically converted into an object and then into JSON.
 * So, for example, echoing "path=GET:/math/sum one=1 two=2" will send the
 * JSON string '{ "path": "GET:/math/sum", "one": 1, "two": 2 }' to the API.
 * The result will be printed to the console.
 * Use Ctrl+D to close the console.
 */

var WebSocket = require('ws');

process.stdin.setEncoding('utf8');

var port = process.argv[2] || 8080;

var ws = new WebSocket('ws://localhost:'+port);
ws.on('message', function(data, flags) {
	console.log(data);
});



( run in 0.344 second using v1.01-cache-2.11-cpan-05444aca049 )