I need something simillar to this:
var client = new UdpClient();
IPEndPoint ep = new IPEndPoint(IPAddress.Parse("23.114.44.195"), 11000);
client.Connect(ep);
byte[] data = Encoding.ASCII.GetBytes("test");
client.Send(data, data.Length);
The listener runs on that IP at PORT: 11000, but i don't want to port forward in my router (because I want to publish this app).
So, here is the question: How to send string via UDP without Port Forwarding?
You can use NAT hole punching, which doesn't require manual port forwarding configuration. It's quite simple technique. Please note that remote endpoint (receiver) should implement it too, not just sender.
In the simplest case, it works as:
[sender] <-> |internet| <-> [remote router with NAT] <-> [receiver]
Please note sender
is not behind NAT.
To punch a hole from senderIP:portX
to receiverIP:portY
:
sender
binds to portX
and waits for communication initialisation from receiver
. receiver
binds to portY
and sends a dummy packet to senderIP:portX
. sender
gets receiverIP
(which is actually its router IP) and portY
from the package and now sends meaningful data to this address. NAT remembered that communication with senderIP:portX
was going from receiver
s local IP and portY
, so all data coming from senderIP:portX
to the router's portY
will be redirected to receiver
s local IP.
For the case when both sender
and receiver
are behind NATs, you need a rendezvous server, for details check the link.