[Haxe][UDP]Any Haxe UDP implementation works for OpenFL?

I need to build an UI for some data sent via UDP. While there are two UDP implementations on github, I find neither of them compile with my OpenFL project:


I just dropped the source codes into my Source folder.

My code for using hxnet:

package;

import hxnet.udp.*;
import hxnet.protocols.*;
import hxnet.interfaces.*;
import hxnet.base.*;

class MyClient extends hxnet.protocols.Telnet
{

override private function lineReceived(line:String)
{
    trace(line);
}

public function new()
{

    var client = new hxnet.udp.Client();
    client.protocol = hxnet.interfaces.protocol; // set the protocol we want to use
    client.connect("127.0.0.1", 8000);
    client.blocking = false; // important for gui clients
    
}

}

And it throws the following errors:

Source/MyClient.hx:20: characters 26-51 : Unknown identifier : hxnet
Source/hxnet/udp/Client.hx:32: characters 2-25 : hxnet.interfaces.Protocol has no field makeConnection (Suggestion: loseConnection)
Source/hxnet/udp/Client.hx:86: characters 3-23 : hxnet.interfaces.Protocol has no field makeConnection (Suggestion: loseConnection)
Source/hxnet/udp/Connection.hx:10: lines 10-49 : Field isOpen needed by hxnet.interfaces.Connection is missing
Source/hxnet/udp/Connection.hx:18: lines 18-40 : Field writeBytes has different type than in hxnet.interfaces.Connection
Source/hxnet/udp/Connection.hx:18: lines 18-40 : bytes : haxe.io.Bytes -> ?writeLength : Bool -> Bool should be bytes : haxe.io.Bytes -> Bool

Any thoughts on how to make UDP work? I’m kind of desperate. The only protocol that the other app supports is UDP.

You could always try UdpSocket as found here. It would mean doing all that stuff manually, but that should have less problems versus the other two.

There is also openfl.net.Socket but not sure how developed that is. I would personally use the one used in Haxe as that is likely more widely supported.

As for the errors: The interface doesn’t have the field makeConnection found here. You can only assume by that that the library is out-of-date. So I personally wouldn’t use it.

Thanks for the reply. I’ve tried the haxe UdpSocket, but it raises “not available on this platform” message, and I am targeting CPP. I looked at the source and it seems not implemented.

I’m trying to use file system to share the data. The output app writes to a text file and my app read from that file every time the other app writes. I use sys.io.File, but keep getting the same data while the data in the file is changing. I assume this is because the file is being preloaded every time the app runs? But I cannot be sure. Any suggestion on how I can correct this? Maybe some asynchronous file readers? Thanks a million.

If you’re targeting C++, you can use an ENTER_FRAME event that checks when the file was last modified, and then reload it:

private function onEnterFrame(e:Event):Void
{
    var fileModTime = sys.FileSystem.stat("myFile.txt").mtime;
    if (fileModTime > lastModTime)
    {
        parseFile("myFile.txt");
        lastModTime = fileModTime;
    }
}

Ideally, you would want to send a ByteArray to the server your connected to, have the server manipulate the data accordingly, and then send it back to each connected client, without dealing with files. Problem with streaming files is the latency, because you need to first read the file, which can take time away and that can cause “lag”.

The file approach is only really suitable if you’re sharing levels, for example.

In fact, for now these two lines are called inside my ENTER_FRAME function:

var tmpWaveRaw = sys.io.File.getContent("assets/wave.txt");
trace(tmpWaveRaw);

And the output is always the same value, although the file is changing. If I restart the app, the value changes to whatever the file value was when the app started.

I understand the latency issue. In my case the data transmission can be as unreliable as it can be, so I just read from the file at any rate I need.

Hi, regarding the ModTime, I posted my experiment on my SO thread, under “update” section.

The app just doesn’t seem to recognize the changes while it is running.