Skip to content
This repository has been archived by the owner on Sep 24, 2023. It is now read-only.

wronex/node-wsock

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

wsock

wsock is an easy to use WebSocket implementation, as described by RFC 6455, except for protocol extensions. It features both WebSocket server and client.

Installation

$ [sudo] npm install wsock

Usage

Server example

var wsock = require('wsock');

var server = wsock.createServer();

server.on('connect', function(connection) {
	console.log('wsocket connected:', wsocket.socket.remoteAddress, 
		'(' + server.connections, '/', server.maxConnections + ')');

	wsocket.on('data', function(data, isBinary) {
		console.log('Recieved:', data.length > 64 ? data.length + ' bytes' : data);
		wsocket.send(data);
	});
	
	wsocket.on('close', function() {
		console.log('wsocket closed', 
			'(' + server.connections, '/', server.maxConnections + ')');
	});
	
	wsocket.on('error', function(ex) {
		console.error('wsocket error:', ex);
		throw ex;
	});
});

server.on('error', function(ex) {
	console.error('wsocketServer error:', ex);
	throw ex;
});

server.listen(80, 'localhost');

Client example

var wsock = require('wsock');

var client = wsock.connect({port: 80, host: 'localhost'}, function() {
	console.log('wsocket open', client.readyState);
	client.send('Hello World!');
});

client.on('data', function(data, isBinary) {
	console.log('Recieved:', data.length > 64 ? data.length + ' bytes' : data);
});

client.on('close', function() {
	console.log('wsocket closed');
});

client.on('error', function(ex) {
	console.error('wsocket error:', ex);
});

console.log('Client running');

License (MIT)

Copyright (c) 2012, wronex.

Author

[wronex][0] [0]: http://www.wronex.com/

About

An implimentation of the Web Socket protocol, both as server and client.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published