none
Why Server and Clients not communicating if clients on different network ? RRS feed

  • Question

  • i make sample c#   Console application  for communication between clients and server using c# socket programming.
     
    communication mean : (in my program the string "hello world" is send by client and server receive and response back to server .)
     
    Clients and Server can communicate  with each other when both on same network ,just IP different. 
     
    but Clients not sending the string to the server if clients are on other network /Different Network .
    e.g think same as now you and me are on different network. i make my pc server and you make your pc client. run my sample {client.cs} exe  ,in client.cs there is My server IP include like below:

     string serverDNS = "xxx.xx.xx.xx"; // here i put server IP. .
                    int port = 0;
                    System.Int32.TryParse("11000", out port);

    try
                    {
                        IPAddress[] addrs = System.Net.Dns.GetHostAddresses(serverDNS);
                        foreach (IPAddress addr in addrs)
                        {
                            if (addr.AddressFamily == AddressFamily.InterNetwork)
                            {
                                endpoint = new IPEndPoint(addr, port);
                                break;
                            }
                        }
                    }

    and i also run on my server pc  my sample. in that case i will not able to receive a string "hello worlds" from you (Client pc)>>> this is a problem..
    can any body help me please ???

    Wednesday, November 26, 2014 1:53 PM

Answers

  • When I ping I can't tell if I'm ping youi computer or another computer.  Depending on 1st octet will indicate if the IP is an internal local IP or Internet IP. When I'm not sure I disconnect the receiving end to determine if the ping response is really coming from the correct computer.

    I just solved an issue last month at work where two devices were assigned the same IP.  I've been doing this for a long time and found lots of cases were the ping response was coming from a different device than I suspected.  Lots of times two devices had the same IP.  I always start my debugging looking for the simple stupid mistakes before looking at the ones that are harder to find and fix. 


    jdweng

    Wednesday, November 26, 2014 5:04 PM

All replies

  • Make sure you can PING the computer before trying you code.  Pin by both IP address and computer name to see which one(s) works.  You can run ping from a cmd.exe window

    > ping 192.1.1.1

    or

    > ping ComputerName


    jdweng

    Wednesday, November 26, 2014 2:05 PM
  • you mean  have to ping Server IP ? Or Clients ip??? 
    Wednesday, November 26, 2014 2:16 PM
  • I have ping From  my computer .i ping server ip in cmd.exe. its give timeout 4 time..but i receiving  the response from that IP  using my application.. i was client and the ip which i pinged just now.this was a server IP.. i receive Timeout but when i run the my application on both client and server i also received Response Back from server too.

    (here me and server are on same network ,just ip different. )

    now problem if i use other client ip which is on different network,e.g i use your PC external IP. and ping ,i recieve timeout 4 time and also not get any response from client too. 

    why this ??? 

    Wednesday, November 26, 2014 2:22 PM
  • Make sure you don't have duplicate IP addresses or talking to a diffferent device.  Turn off the device you "think" is responding and then ping again.  You can have ping woring one direction and not the other but that is unusual.  Sometimes when you ping in one direction is can cause the ping to start working in other direction so try the direction that failed again.

    jdweng

    Wednesday, November 26, 2014 2:32 PM
  •  It's going to be a firewall problem. From a networking perspective, there is technically no difference in sending to a host on the LAN vs. a host on a different LAN, via a WAN. SO if it works locally then the problem is not in my  code, it will be a firewall setting.

    But I just don't know Server fireWall i have to setting or Client PC firewall. and how setting. 

    Wednesday, November 26, 2014 2:38 PM
  • Don't assume a firewall issue.  There are hundreds of reasons for a message not to complete.  Get ping working first which in most cases will get through a firewall.  Make sure you test ping with both IP address and Computer name because in some cases one will work while the other will fail.

    jdweng

    Wednesday, November 26, 2014 3:28 PM
  • are you sure? then i give you my ip and you ping its then tell me whats going on.. 

    this way will work??

    Wednesday, November 26, 2014 3:31 PM
  • When I ping I can't tell if I'm ping youi computer or another computer.  Depending on 1st octet will indicate if the IP is an internal local IP or Internet IP. When I'm not sure I disconnect the receiving end to determine if the ping response is really coming from the correct computer.

    I just solved an issue last month at work where two devices were assigned the same IP.  I've been doing this for a long time and found lots of cases were the ping response was coming from a different device than I suspected.  Lots of times two devices had the same IP.  I always start my debugging looking for the simple stupid mistakes before looking at the ones that are harder to find and fix. 


    jdweng

    Wednesday, November 26, 2014 5:04 PM