COMMUNITY

Connecting to a server with ipv6 address

I am able to send a udp packet to a server I made in golang using “localhost” as the host address. I can’t figure out how I am supposed to replace “localhost” with my ipv6 address. There isn’t a valid way that I have found for haxe to accept something like this “2001:0db8:85a3:0000:0000:8a2e:0370:7334” as an address. I tried figuring out my public ipv4 address but I don’t actually receive anything via my program or through a packet sending program I downloaded for debugging. The ipv6 address works in the packet sending program and my server can receive the udp packets fine. If anyone can point me in the right direction here I would really appreciate it.

I am using the following versions
flixel(4.4.2)
hscript(2.2.0)
lime(6.4.0)
openfl(8.3.0)
haxe(3.4.7)

If I understand correctly you are sending a udp packet from the server to your computer?
That’s going to be difficult in ipv4 since very very likely that’s the address of your router not your computer.
I assume ipv6 would work for that.

How are you sending the packet, and which version of hxcpp do you have?
There was some commits some time ago in hxcpp about ipv6 support.

Not really a solution for your problem if udp is required, but with tcp you could open a connection to the server and the connection would take care of getting the response back to your computer.

So I am sending a udp packet from a client (written in haxe) to a server I have written in golang.

Client code that sends a packet

package;

import sys.net.UdpSocket;
import sys.net.Address;
import sys.net.Host;
import flixel.FlxState;
import flixel.FlxG;
import haxe.io.Bytes;
import cpp.NativeSocket;

class PlayState extends FlxState
{
	var testplayer:Player;

	var udpSock:UdpSocket = new UdpSocket();
	var hostAddr:Address= new Address();

	var message:Bytes;
	var buffer:Bytes;

	override public function create():Void
	{
		testplayer = new Player(100, 100);

		this.add(testplayer);

		message = Bytes.ofString("Hi");
		buffer = Bytes.alloc(1024);

		udpSock.bind(new Host("0.0.0.0"), 6666);
		
		hostAddr.host = new Host("localhost").ip;
		hostAddr.port = 9090;

		trace(hostAddr.host);

		udpSock.sendTo(message, 0, message.length, hostAddr);
		message = Bytes.ofString("one");
		udpSock.sendTo(message, 0, message.length, hostAddr);
		message = Bytes.ofString("two");
		udpSock.sendTo(message, 0, message.length, hostAddr);
		message = Bytes.ofString("three");
		udpSock.sendTo(message, 0, message.length, hostAddr);
		message = Bytes.ofString("four");
		udpSock.sendTo(message, 0, message.length, hostAddr);
		message = Bytes.ofString("five");
		udpSock.sendTo(message, 0, message.length, hostAddr);

		super.create();
	}

	override public function update(elapsed:Float):Void
	{
		super.update(elapsed);

		trace(testplayer.getState()); 

	}
}

This works perfectly for sending the packet to my server running on the same machine. However it isn’t going to work out for something like a game.

I’m not sure about which hxcpp version I am using. How would I check that?

You can check the hxcpp version using haxelib, haxelib list hxcpp.

I checked and (at least in recent haxe) Host on cpp can take an ipv6 address, but you can’t use the int ip field,
so since UdpSocket requires an int address I don’t think you can do it yet.
You might want to open an issue about that https://github.com/HaxeFoundation/haxe/issues.

Is that for a game, what kind is it? Often tcp speed would be enough and you need the reliability, though if it’s for something like a fast pace shooter tcp is not going to cut it yeah.

Yeah it’s for a fast paced game. I was leaning towards tcp, but it isn’t fast enough for reliable movement/combat over the network. I guess I will open an issue for this, I wanted to check here first and make sure I wasn’t missing something obvious. Thanks for your help!

This is my hxcpp version by the way.

hxcpp: 3.2.205 3.3.49 3.4.64 [3.4.188]