Santiago V.
Santiago V.

Reputation: 1118

WebSockets + Haxe?

I need to develop an application using WebSockets and Haxe.
I came upon this lib: http://lib.haxe.org/p/hxWebSockets
But it's outdated.
Then I found this blog post: http://bp.io/post/322
But the links to the code are broken :(

So, anyone out there knows any other WebSocket resource for Haxe?
If not, does someone has a clue where to start looking to start implementing my own solution?

Thanks!

Upvotes: 1

Views: 2123

Answers (4)

dganti
dganti

Reputation: 305

I am using haxe for a websockets application and using the js libraries:

import js.html.WebSocket;

Using the following function to connect to the server.

private function connect() {
    trace("Calling connect");
    try {
    websocket = new WebSocket(connectionString());
    websocket.onclose = onClose;
    websocket.onerror = onServerConnectionError;

    var openStream = initializeElementStream(cast websocket, "open");
    openStream.then(onOpen);
    var eventStream = initializeElementStream(cast websocket, "message");
    eventStream.then(onMessage);

    var closeStream = initializeElementStream(cast websocket, "close");
    closeStream.then(onClose);

    var errorStream = initializeElementStream(cast websocket, "error");
    errorStream.then(onServerConnectionError);
    }catch(err : Dynamic) {
        trace("Error establishing connection " + err);
    }
    trace("Connection successful");
}

Will this work for you. I am sticking to standard js libraries for my project. This has worked for me since the project has no external dependencies.

Upvotes: 1

TiagoLr
TiagoLr

Reputation: 3074

I recently started using Haxe-Js-Kit and it has decent bindings for a lot of nodejs libs including Socket.IO.

https://github.com/clemos/haxe-js-kit/

Make sure you use the dev branch for development as it is quite more advanced than the haxelib or master branch.

Upvotes: 0

dagnelies
dagnelies

Reputation: 5329

The lib you mentioned is indeed outdated. Luckily, someone made a new one, supporting the latest websocket protocol:

http://lib.haxe.org/p/WebSocket

...however, it's still a bit lower level than nodejs/socket.io

Upvotes: 1

stroncium
stroncium

Reputation: 1430

If you use node.js as a platform, I'd recommend you to make bindings to socket.io. If you use another platform, I'd recommend to use socket.io as a reference implementation, or just port it to haxe, which shouldn't be that hard.

Upvotes: 1

Related Questions