uws 9.147.0

Extern definitions for npm uws

Released 2018-04-22.

To install, run:

haxelib install uws 9.147.0

See using Haxelib in Haxelib documentation for more information.

Maintainerterurou
Websitehttps://github.com/DenkiYagi/haxe-extern-uws
Current version9.147.0
StatisticsInstalled 2 times
LicenseApache
Tags

README.md

Haxe extern for uws

Haxe extern definitions for npm uws.

Install

haxelib git uws https://github.com/DenkiYagi/haxe-extern-uws

Example 1 : Websocket

Server

var server = new UwsServer({ port: 3000 });
server.on(ServerEvent.Listening, function () {
    trace("Listening started");
});

server.on(ServerEvent.Connection, function (ws) {
    ws.onping = function () {
        trace("ping");
    }
    ws.onpong = function () {
        trace("pong");
    }
    ws.onmessage = function (event) {
        trace("message");
        trace(event);
    }
    ws.onclose = function (event) {
        trace("close");
    }
    
    ws.ping();

    // send text message
    ws.send("hello");

    // send binary message
    ws.send(Buffer.from("こんにちわ世界", "utf-8"), { binary: true });

    haxe.Timer.delay(function () {
        ws.terminate();
    }, 2000);
});

server.on(ServerEvent.Error, function (err) {
    trace(err);
});

Client

var client = new Uws("ws://localhost:3000/");

client.onopen = function () {
    client.send("hello");
}

client.onmessage = function (event) {
    trace("message");
    trace(event);
}

client.onping = function (message) {
    trace("ping");
    trace(message);
}

client.onpong = function (message) {
    trace("pong");
    trace(message);
}

client.onclose = function (event) {
    trace("close");
    trace(event);
}

client.onerror = function (err) {
    trace("error");
    trace(err);
}

Example 2 : HTTP Server with Koa.js

var app = new Koa();
app.use(function (ctx) {
    ctx.body = "Hello World!";
});

var server = UwsHttp.createServer(app.callback());
server.listen(3000);