views:

49

answers:

6

Hi,

I have made a simple server running locally using tcplisten and it works fine over local network e.g. (127.0.0.11:8888).

But how do I now receive connections to the server from the internet, what ip and port do I set??

Thanks

A: 

You need to set a firewall rule up on your network to forward any traffic coming into your public IP on that port to be forwarded to the internal IP address of the machine running your server application.

Achilles
+2  A: 

You can still use 8888. Just make sure that your firewall settings permit incoming connections to that port.

lxe
A: 

Your server will need to run on machine with real-live IP. The server can bind itself to default IP or you can explicitly provide the IP address to bind to. Ports are not a problem as long as no other server application is listening on the same IP:Port.

this. __curious_geek
The problem is the application would be used by a few people and having to set up the router would put most people off as they dont understand port forwarding. So how do such applications like chat work then? Im guessing they keep a constent connection with a server on the internet with a domain/staic ip and that deals with all that data and sends it to the correct client? Thanks for the help so far people!
arbme
Chat works because the client piece makes a call out to the server, not the other way around. If you're selling a server, the customer needs to be able to set up the server just like they would a web or mail server.
Byron Sommardahl
+2  A: 

Assuming this is a windows machine, and assuming that it is a simple network (i.e. that your firewalls are forwarding connections from 8888 to the internal IP, or that the machine has an appropriate externally exposed interface) you should be able to connect via the public interface to your machine. If you are instancing your listener with a particular IP address (127.0.0.1) you may be preventing connections.

You can use IPAddress.Any or save a list of IPs in a configuration and load those from disk.

IPEnpoint e = new IPEndPoint(IPAddress.Any, 8888)
TcpListener l = new TcpListener(e);
fauxtrot
+1  A: 

You may need to check whether you are behind some kind of NAT box. You can do this by checking your own ip from an internet site like whatismyip and comparing it to the ip of your machine.
You should also change your firewall rules to allow incoming connections.

PS : Web browsers by default connect to port 80. You can connect to different ports by mentioning port in the url like - http://www.example.com:8080/index.html .

apoorv020
+1  A: 

There are a few things you need to do:

1) Log in to your Router and set up port forwarding:

  1. From a computer that is connected to the router...
  2. Find out your router's local network IP address and connect to that address in your web browser (common ip's are 10.0.1.1 or 10.0.1.254 or 192.168.1.1 or 192.168.1.254).
  3. Find the menu option in the router that allows you to set up port forwarding.
  4. Add a port to forward and enter your server's network IP address (should be close to the router's ip address) and desired port number.
  5. Save and close.

2) Add an exception to your firewall to allow TCP traffic from your desired port.

3) Find out the public IP address of your router (try http://www.myipaddress.com) and attempt to connect to your server using that address.

That should be all you need to do.

Byron Sommardahl
Thanks very much for the help. Im fine with doing port forwarding its just other people would be put off by having to do this. So I think Ill have to have the server maintain a connection to a server with a doman/static ip and have it work that way to save people moaning :) Thanks again!
arbme
@arbme: But if you are the only one using the router, you can forward the router's port 80 to your machine ip:8888. The users wont even know anything.
apoorv020
Thanks but most of the users of the app will be behind a router so its easier for all if I invest in a server to handle this side of it to make it simplier to use for all.
arbme