websocket 2.0.2

HTML5 websocket support for sys platforms. Unblocked and threaded servers for neko.

Released 2016-05-13.

To install, run:

haxelib install websocket 2.0.2

See using Haxelib in Haxelib documentation for more information.

Maintaineryar3333
Websitehttps://bitbucket.org/yar3333/haxe-websocket
Current version2.0.2
StatisticsInstalled 194 times
LicenseLGPL
Tags

README.md

websocket

WebSocket implementation for sys platforms. Unblocked and threaded servers for neko.

Example

See tests folder. Quick code below:

// Haxe / Neko

class MyConnection extends neko.net.WebSocketServerLoop.ClientData
{
	// your custom fields if you need data associated to each connection
}

class Main
{
	static function main()
	{
		var serverLoop = new neko.net.WebSocketServerLoop<MyConnection>(function(socket) return new MyConnection(socket));
		
		serverLoop.processIncomingMessage = function(connection:MyConnection, message:String)
		{
			trace("Incoming: " + message);
			// use "connection.ws" to send answer
			// use "serverLoop.closeConnection(connection.ws.socket)" to close connection and remove socket from processing
		};
		
		serverLoop.run(new Host("localhost"), 5121);   
	}
}
// JavaScript or Haxe

var ws = new WebSocket("ws://localhost:5121"); // use native js WebSocket class (js.html.WebSocket in haxe)
ws.onopen = function()
{
	console.log("CONNECT");
	ws.send("TestString");
};
ws.onmessage = function(e)
{
	console.log("RECEIVE: " + e.data);
};
ws.onclose = function()
{
	console.log("DISCONNECT");
};