Websocket in haxe-java?

I can’t find any useful library to use websocket in haxe-java from haxelib.

are there any help?

use for android-target.

@Zhan you can use any existing websocket java library. Just tell Haxe where to find your jar file by using the -lib tag in hxml

Have you looked at this repo yet?

I haven’t tried to use it, but @ianharrigan maintains HaxeUI and does great work.

I did for other target ,it’s seem not support java target.

It seems setBlocking isnt implemented in haxe yet.

Exception in thread "main" Haxe Exception: Not implemented
        at haxe.lang.HaxeException.wrap(HaxeException.java:43)
        at sys.net.Socket.setBlocking(Socket.java:199)
        at hx.ws.WebSocketServer_MyHandler.start(WebSocketServer_MyHandler.java:61)

Maybe some other things too…

@ianharrigan,current I use your lib for HL target ,it’s seem good .

Good to know it works on HL :slight_smile:

It would be good to get it working on all haxe targets though, as that kinda the purpose of it (and haxe itself ofc)… Ill check it out a little when i get time (i dont think i test c# either)… if i remove the call to “setBlocking” i get an exception elsewhere… :confused:

Cheers,
Ian

I suggested you can improve your code use MainLoop.hx to replayce your custom loop use while(true)…if you had time.

1 Like

Ok, so ive added basic (verrry basic) java support (via NIO) and c# aswell… im pretty sure both implementations could be vastly improved and they will only work for hxWebSockets (ie, the NioSocket class cant be “dropped in” for the normal socket class - lots will break)…

Still, its a start - and in my tests all seems “fine” (but i havent done any deep testing at all) - just messing with different targets for clients and servers… all of which seemed to work for the basic echo:

Let me know if they work, and more importantly, when they dont and what we think is a good way to improve them - having a maintained web sockets lib that works for all available haxe targets is certainly something that would be nice. :slight_smile:

Cheers,
Ian

@ianharrigan can you compile to java target use the rc3 version?

Hmm, yeah, it doesnt compile:

src\hx\ws\WebSocketServer_start_54__Fun.java:21: error: illegal character: '`'
		`this.tick();
		^
src\hx\ws\WebSocketServer_start_54__Fun.java:23: error: illegal character: '`'
		haxe.root.Sys.sleep(`this.sleepAmount);
		                    ^
src\hx\ws\WebSocketServer_start_54__Fun.java:23: error: ';' expected
		haxe.root.Sys.sleep(`this.sleepAmount);
		                     ^
src\hx\ws\WebSocketServer_start_54__Fun.java:23: error: illegal start of expression
		haxe.root.Sys.sleep(`this.sleepAmount);
		                         ^
src\hx\ws\WebSocketServer_start_54__Fun.java:23: error: ';' expected
		haxe.root.Sys.sleep(`this.sleepAmount);

I wonder where that character is coming from… Its not he haxe source i dont think… Maybe some strange issue with hxJava?? Im on haxe 4.0.0-rc.3+e3df7a448

That’s probably the same issue as was reported in [java]compile error? · Issue #8617 · HaxeFoundation/haxe · GitHub.

1 Like

Yup looks exactly the same, didnt know about that issue. Was certainly working at some point, though i dont remember what version of haxe4 that was.

EDIT: added a minimal example to that issue