none
Communicating (by ip address) between computers on different networks using C#

    Question

  • I'm creating a simple 2d grid game and want to allow users to connect the game by inputting my Ip address.

    So far what I've been able to find are answers only having to do with connecting using the same network, but I want it to be able to connect through the internet and be able to do so with 3 or 4 other computers using winforms in C#.

    Can anyone point me in the right direction?  Or maybe even help me a little bit?

    Saturday, November 09, 2013 9:31 AM

Answers

  • @Christoper82
    Well from what I have given you:
    It being a simple 2d grid game, Like Connect Four or Tic Tac Toe, What approach would you do? Host the server? Have a central public server?

    I'm thinking hosting one is the easiest because I will only have 3-5 People in the game at once.

    The complexity of the application is irrelevant. It can be a ping or high-end, network based Distributed Processing. Connection over the internet are difficulty. This is not even a programming Problem, but a mater of Routing and visibility/accesibility.

    The programming parts is extremely easy. Indeed you can just write code for communication over your local network and that is it. It will work just as well to computers connected to the same switch as it will for computers half the planet appart.
    I would just leave it at that. If somebody wants to play over the internet, he can deal with getting his Server accesible through NAT or getting his computer a public IP adress.


    Let's talk about MVVM: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/b1a8bf14-4acd-4d77-9df8-bdb95b02dbe2 Please mark post as helpfull and answers respectively.

    Sunday, November 10, 2013 2:39 AM
  • You need a route between to computers for a connection to complete between a client and server using IP addresses.  The route is determined by the IP address of the interface (the ethernet card adapter on the PC) and the mask one the interface.  You can see the IP address and mask by running the following command in a cmd.exe window

    ipconfig/all

    Often the IP Address and masks are setup incorrect for two PC to communicate with each other. The problem becomes more complicated when a PC has more than one network card, or when the computers are connected in a network with multiple routers and multiple servers forwarding the connection (a multiple hop network).  If you are trying to connect computer across the internet it is only possible if the internet provider server allows the IP address to pass.  For example and IP address starting with 172 is a local IP address is a local IP address that isn't allowed to be sent over the internet while an IP address starting with 192 is allowed to be sent over the internet.

    Normally the place to start is by using PING to see if there is a route.  If PING doesn't work it either indicates there is no route or the hardware is configured improperly.    To connect two computers directly you need to either go through a hub or use a cross over cable.  If you connect two comaputers with the wrong type cable PING will not work.

    If Ping works and your application doesn't work there could be a lot of causes to this problem.  the most common these days are firewall blocking the port number.


    jdweng

    Sunday, November 10, 2013 4:10 AM

All replies

  • Thank you. I'll give them a read.

    Btw, do they both go into detail about how to use them in Winform? Or is it the same for console/winform/wpf etc?
    Saturday, November 09, 2013 10:27 AM
  • Network is the same, wheter you use Winform, WPF or MCL.

    However connection over the internet is not a trivial task. Especially if the Server is behind a router. Think thrice before you try to add that.

    Even professional game Companies fail at this problem from time to time. Most often they just avoid it by using a central, publically accesible Server for coordination and some Hole Punching or just running the entire game on thier servers (each participant is a client, none the server).


    Let's talk about MVVM: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/b1a8bf14-4acd-4d77-9df8-bdb95b02dbe2 Please mark post as helpfull and answers respectively.


    Saturday, November 09, 2013 1:01 PM
  • @Christoper82
    Well from what I have given you:
    It being a simple 2d grid game, Like Connect Four or Tic Tac Toe, What approach would you do? Host the server? Have a central public server?

    I'm thinking hosting one is the easiest because I will only have 3-5 People in the game at once.

    Saturday, November 09, 2013 5:48 PM
  • <copied>

     Btw, do they both go into detail about how to use them in Winform? Or is it the same for console/winform/wpf etc?

    <end>

    There are books on Socket and WCF programming in C#. You'll have to use Bing or Google to find them.

    Saturday, November 09, 2013 7:28 PM
  • @Christoper82
    Well from what I have given you:
    It being a simple 2d grid game, Like Connect Four or Tic Tac Toe, What approach would you do? Host the server? Have a central public server?

    I'm thinking hosting one is the easiest because I will only have 3-5 People in the game at once.

    The complexity of the application is irrelevant. It can be a ping or high-end, network based Distributed Processing. Connection over the internet are difficulty. This is not even a programming Problem, but a mater of Routing and visibility/accesibility.

    The programming parts is extremely easy. Indeed you can just write code for communication over your local network and that is it. It will work just as well to computers connected to the same switch as it will for computers half the planet appart.
    I would just leave it at that. If somebody wants to play over the internet, he can deal with getting his Server accesible through NAT or getting his computer a public IP adress.


    Let's talk about MVVM: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/b1a8bf14-4acd-4d77-9df8-bdb95b02dbe2 Please mark post as helpfull and answers respectively.

    Sunday, November 10, 2013 2:39 AM
  • You need a route between to computers for a connection to complete between a client and server using IP addresses.  The route is determined by the IP address of the interface (the ethernet card adapter on the PC) and the mask one the interface.  You can see the IP address and mask by running the following command in a cmd.exe window

    ipconfig/all

    Often the IP Address and masks are setup incorrect for two PC to communicate with each other. The problem becomes more complicated when a PC has more than one network card, or when the computers are connected in a network with multiple routers and multiple servers forwarding the connection (a multiple hop network).  If you are trying to connect computer across the internet it is only possible if the internet provider server allows the IP address to pass.  For example and IP address starting with 172 is a local IP address is a local IP address that isn't allowed to be sent over the internet while an IP address starting with 192 is allowed to be sent over the internet.

    Normally the place to start is by using PING to see if there is a route.  If PING doesn't work it either indicates there is no route or the hardware is configured improperly.    To connect two computers directly you need to either go through a hub or use a cross over cable.  If you connect two comaputers with the wrong type cable PING will not work.

    If Ping works and your application doesn't work there could be a lot of causes to this problem.  the most common these days are firewall blocking the port number.


    jdweng

    Sunday, November 10, 2013 4:10 AM