I made a chat app in C# using the UDP protocol. I don't want to use TCP. But it is only working within my own network/wifi. I made this for myself and my friend, or possibly anyone else who downloads it, and it isn't working. Do I have to portforward or something? To port forward doesn't make sense because all other programs I download don't ask me to portforward :P . How would I get this to work over a long distance? Here is the code I used:
Receiving the data:
static UdpClient UdpReciever = new UdpClient(PORT);
static byte[] data = new byte[512];
static void Main(string[] args)
{
while (true)
{
IPEndPoint EP = new IPEndPoint(IPAddress.Any, PORT);
data = UdpReciever.Receive(ref EP);
Otherclass oc = new Parser();
Otherclass.Parse(data);
}
}
public class Otherclass
{
public static void Parse(Byte[] data)
{
string received = Encoding.ASCII.GetString(data);
Console.WriteLine(received);
}
}
For sending the data I'm using this code:
IPEndPoint ep = new IPEndPoint(IPAddress.Parse(this.Ip), port);
Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
client.SendTo(ex.packetdata, ep);