views:

90

answers:

3

Hey guys,

I'm following a tutorial @ http://www.geekpedia.com/tutorial239%5FCsharp-Chat-Part-1---Building-the-Chat-Client.html to try and gather the basics of networking. For those not wanting to hit the jump, it's a quick tut demonstrating how to program a simple client-server-model chat application.

When I try and run the code in the tut, it works fine as long as both the client and the server are on the same network, but the second I try and do it externally (getting a mate to run the client app, and running the server app my side), it all goes to pot. The fact that the code works when in the same network leads me to believe that it's not a coding issue, but an issue with the way my network is set up.

I'm trying to run the server on my IP address at port 21719, which I have opened, but still other people can't connect to my server, not able to get any form of response at all.

The code (from the tut) that is being used for the server to listen to connections is:

public void StartListening()
        {


            IPAddress ipaLocal = ipAddress; //ipAddress is parsed from txtIP


            tlsClient = new TcpListener(ipaLocal, 21719);


            tlsClient.Start();


            ServRunning = true; //for the running loop

            // Start the new tread that hosts the listener
            thrListener = new Thread(KeepListening);
            thrListener.Start();
        }

Now, the tutorial does actually point out that IPAddress ipaLocal = ipAddress;

Will cause issues on some configurations, and I'm beginning to fear that my configuration may be included in that.

So, does anyone have any solution for me?

Thanks, Sam

A: 

Are you having people use your external (internet) IP address? (See yours here.)
Have you pinholed your router to forward all communications from port 21719 to your server?

Spencer Ruport
Yeah, I have, to both.
SamuelRSmith
Well if the app works on your LAN the problem has to do with connectivity. Figure out what's blocking the connection and everything should work smoothly.
Spencer Ruport
A: 

Some tips:

  1. What kind of operating system are you using? Please check the Scope and/or Profiles (under Advanced tab) of your firewall rule.
  2. While your friend is trying to telnet to the port (connect to the im server) monitor the traffic using Wireshark or Network Monitor (Wireshark have problems with Vista and Win 7). If you don't see anything hitting your machine the problem is probably on the router side. Double check the settings - you said you set the forward rule (NAT) but did it also set the rule on firewall of your router?
kyrisu
+1  A: 

What is the local IP address that you're using? (ipAddress) If it's 127.0.0.1, that's not correct (I don't know how it would work internally either, but Windows seems to use magic from time to time). Also, if you have multiple NICs in your local machine, maybe the port forwarding is only set up to forward to one of them, and you're using the IP of the other?

If that's not the problem, here are a few generic suggestions:

  1. Grab a copy of netcat. It's a small network testing util whose only job is to form a simple TCP connection. That will allow you to eliminate your code as a variable in all this. If netcat can form a connection, then you know the problem is your code. If not, you've confirmed that it's your router.

  2. You can use WireShark (or TShark) to look for ICMP packets. Capture ICMP packets on the remote machine. If you get "Destination Unreachable" from the router, you've again proved that it's your router.

As Spencer said you need to make sure Port Forwarding is setup on your router, to forward all packets that come in on port 21719 to your internal machine. As for exactly how to do that, it's hard to say without knowing what type of router.

HiredMind