0

I am new to networking, and I'm sorry if this is a dumb question.

I'm trying to make a simple p2p chat application in C# using sockets. I don't want to send the messages through a server, but instead, the clients will be talking directly to each other.

Of course, I will need a server to keep track of the client addresses, so one client actually knows where to find an other one, but that's only an IP address, and to establish a socket connection, I will also need a port. I don't want the users to have to mess around with port forwarding in the router.

So my question is, how do I create a connection between two different networks in C# using Sockets?

Rand Random
  • 7,300
  • 10
  • 40
  • 88
Lázár Zsolt
  • 685
  • 8
  • 29
  • 2
    This question is far too broad. There are countless tutorials on creating chat applications in C#, I'm sure one or more of them will answer your question with a little research. – Equalsk Dec 05 '17 at 13:45
  • This is more of a networking question than a coding question. – Carlos Dec 05 '17 at 13:46
  • all that said, the router part of your question is [discussed here](https://stackoverflow.com/questions/333079/is-there-a-upnp-library-for-net-c-or-vb-net) – Tewr Dec 05 '17 at 13:49
  • For what I understand, your clients are behind different NATs. You will need a NAT traversal solution. I suggest to search for UPnP solutions in C#, A quick search shows there is a library from Mono should be able to do the work. Alternatively, look for WebRTC solution in C#. I think there are some on github. Edit: found some via nuget too. – Theraot Dec 05 '17 at 13:49
  • UPnP seems like a good solution, I'll give it a try. – Lázár Zsolt Dec 05 '17 at 13:57
  • This link can help you. [how-can-i-make-a-browser-to-browser-peer-to-peer-connection](https://stackoverflow.com/questions/7022383/how-can-i-make-a-browser-to-browser-peer-to-peer-connection) – cCcik Dec 05 '17 at 14:08
  • Client and Server have different meanings which often confuse newbies.In your case, one client will be a Listener(often referred to as server) and the other client will be a client.Listener must be started first.You can use any port number.Usually port numbers under 1000 are reserved for specific protocols.I usually use a port number over 10000 that others do not use.See msdn examples. The examples use the socket class but you can use any class that inherits sockets like TcpClient or TcpListener : https://docs.microsoft.com/en-us/dotnet/framework/network-programming/socket-code-examples – jdweng Dec 05 '17 at 14:43

0 Answers0