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:
Please note
sender
is not behind NAT.To punch a hole from
senderIP:portX
toreceiverIP:portY
:sender
binds toportX
and waits for communication initialisation fromreceiver
.receiver
binds toportY
and sends a dummy packet tosenderIP:portX
.sender
getsreceiverIP
(which is actually its router IP) andportY
from the package and now sends meaningful data to this address. NAT remembered that communication withsenderIP:portX
was going fromreceiver
s local IP andportY
, so all data coming fromsenderIP:portX
to the router'sportY
will be redirected toreceiver
s local IP.For the case when both
sender
andreceiver
are behind NATs, you need a rendezvous server, for details check the link.