HaxeFoundation / haxe

Haxe - The Cross-Platform Toolkit
https://haxe.org
6.19k stars 655 forks source link

UDP support on hxcpp #3951

Closed PDeveloper closed 8 years ago

PDeveloper commented 9 years ago

So it seems to be implemented: https://github.com/HaxeFoundation/hxcpp/blob/8bc5141ee3edbad2046fa31fb3be853845a9607c/project/libs/std/Socket.cpp#L138

Yet on the haxe side, there isn't any cpp sys.net.UdpSocket class, only the default one which throws "not implemented" https://github.com/HaxeFoundation/haxe/blob/development/std/sys/net/UdpSocket.hx

Surprised that haxe has no Udp support for this long! : O

P.

ncannasse commented 9 years ago

Ping @hughsando

hughsando commented 9 years ago

I could basically copy the neko file over, but I'm not 100% sure how to test this. I would appreciate a pull-request on this one - should be easy enough if no changes are required on the hxcpp side. Otherwise a working neko example would help.

eminfedar commented 9 years ago

Still not implemented? I got 'primitive not found' error both on neko and cpp.

hughsando commented 9 years ago

Cpp should be giving a "Not available on this platform" error? I need some kind of test program before I can move forwards on this one.

ncannasse commented 9 years ago

@hughsando as soon as you add sendto/recvfrom it should be pretty straightforward: https://github.com/HaxeFoundation/neko/commit/8b40c092246e1e40f9c7d555c967afd9999ab38f

hughsando commented 9 years ago

No test pair lying around on your hard drive?

On Tue, Sep 29, 2015 at 4:05 PM, Nicolas Cannasse notifications@github.com wrote:

@hughsando https://github.com/hughsando as soon as you add sendto/recvfrom it should be pretty straightforward: HaxeFoundation/neko@8b40c09 https://github.com/HaxeFoundation/neko/commit/8b40c092246e1e40f9c7d555c967afd9999ab38f

— Reply to this email directly or view it on GitHub https://github.com/HaxeFoundation/haxe/issues/3951#issuecomment-143978754 .

ncannasse commented 9 years ago

Sorry no, but usually you would create two UDP sockets, then have one sendTo A and B recvFrom will return both the data and A address.

here's some server code snip:

        var addr = new sys.net.Address();
        var buf = haxe.io.Bytes.alloc(2048);
        var lastCheck = haxe.Timer.stamp();
        while( true ) {
            var len = try sock.readFrom(buf, 0, buf.length, addr) catch( e : haxe.io.Eof ) 0;

And the client (in Flash)

        udpSock = new flash.net.DatagramSocket();
        udpSock.connect(udp.host, udp.port);
        udpSock.addEventListener(flash.events.DatagramSocketDataEvent.DATA, function(e:flash.events.DatagramSocketDataEvent) {
            var i = new haxe.io.BytesInput(haxe.io.Bytes.ofData(e.data));
        });
        udpSock.receive();
        var b = new haxe.io.BytesOutput();
        b.writeByte(0);
        b.writeInt32(uid);
        b.writeByte(2);
        udpSock.send(b.getBytes().getData());
whilesoftware commented 9 years ago

This seems like a reasonable template for a test: https://github.com/whilesoftware/hxudp/blob/master/test/UdpTest.hx

hughsando commented 9 years ago

I'm not really after a "unit test" just anything that uses the neko api and actually works.

However, I have added the code completely untested so I guess we can do this in reverse and write the test at the end.

On Wed, Oct 14, 2015 at 4:42 AM, Alan notifications@github.com wrote:

This seems like a reasonable template for a test: https://github.com/whilesoftware/hxudp/blob/master/test/UdpTest.hx

— Reply to this email directly or view it on GitHub https://github.com/HaxeFoundation/haxe/issues/3951#issuecomment-147846661 .

hughsando commented 8 years ago

The udp code is in there now.