Chat Programm with C# via IP-Address. Connecting two Computers in different Networks

Refresh

April 2019

Views

5 time

0

I'm writing a Chat Programm for me and my friend in C# and I don't know how to connect my Computer to a Computer in a different Network. The Code Works fine in my Home Network between two Computers but between two different Networks it doesn't work. I know why it doesn't work, I mean it makes sense, I think I have Connect our Routers somehow with the Standard Gateway or something but I can't find anything on the internet that helps me.

Maybe C# is the wrong language for a Chat App but I'm sure its possible somehow. If someone could please tell me how this works in C# or which language would be better for it?

    private void Form1_Load(object sender, EventArgs e)
    {
        //set up socket
        socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);

        socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);

        //get user IP
        textLocalIp.Text = GetLocalIP();
        //textRemoteIp.Text = GetLocalIP();
    }

    private void buttonConnect_Click(object sender, EventArgs e)
    {
        //binding Socket
        epLocal = new IPEndPoint(IPAddress.Parse(textLocalIp.Text), Convert.ToInt32(textLocalPort.Text));
        socket.Bind(epLocal);

        //connecting to remote IP
        epRemote = new IPEndPoint(IPAddress.Parse(textRemoteIp.Text), Convert.ToInt32(textRemotePort.Text));
        socket.Connect(epRemote);

        //listeninf the specific port
        buffer = new byte[1500];
        socket.BeginReceiveFrom(buffer, 0, buffer.Length, SocketFlags.None, ref epRemote, new AsyncCallback(MessageCallBack), buffer);
    }

0 answers