Has anybody actually got Haxe to work with Websockets?

I have our hosting server setup to run Websockets with Node.js, and tested with pure demo Javascript applications, which work as expected.

However when I try to implement a Websocket application in Haxe it fails to connect to the Server?

I have tried different approaches, from the standard haxe\std\js\html to multiple libraries…

haxe-ws
hxWebSockets
websocket
openfl-websocket

However none of them work, has anybody actually managed to get this implemented?

I have also tried to implement a socket.io approach with the library hxsocketio, although this isnt very cross platform so not the preferred appraoch, however that fails with a missing require socket.io client, which shouldn’t be a client side requirement, however I wasn’t able to resolve this either so went back to Websockets, but I am now stuck!

Did you try the openfl.net.Socket class ?
We used it in our game, and it works well :slight_smile:

Small example :

import openfl.net.Socket;
import openfl.events.Event;
import openfl.events.IOErrorEvent;

class Main
{
	static function main()
	{
		var s:Socket = new Socket();
		s.addEventListener( Event.CONNECT, onConnect );
		s.addEventListener( Event.CLOSE, onClose );
		s.addEventListener( IOErrorEvent.IO_ERROR, onError );
		s.connect( "www.your-game.com", 8080 );
	}

	private static function onConnect( e:Event ) : Void
	{
		trace( "Socket connected" );
	}

	private static function onClose( e:Event ) : Void
	{
		trace( "Socket closed" );
	}

	private static function onError( e:Event ) : Void
	{
		trace( "Socket error" );
	}
}

You can build up a node.js server written with haxe. And use same libraries at two sides.

I have done it using. https://lib.haxe.org/p/WebSocket

Still no joy with the solutions suggested, thanks for the input though.

Maybe there is an issue with the npm versions that the Haxe/Openfl versions require?

It is slightly complicated by the requirement to implement the solution on Plesk which requires the domain to be running through nginx only with no Apache. The node.js solution built into Plesk (17) also utilizes Phusion Passenger.

I know websockets/socket.io does work on the server as I have tried simple demo’s from the web, which succesfully connect, unfortunately the openfl/haxe approach just errors and fails to connect?

What kind of error do you get when trying the sample above ?
Do you use WS or WSS protocol (required when hosted on HTTPS) ?

It just shows Error, and Firefox reports unable to connect to server.

Using WS currently, not on https