If i am not wrong you want to make a chat messenger type application that can work over internet just like gtalk, yahoo, or other IM messengers do ?
There are some points to remeber for that. Lets Define some term here so it would be better to understant what i actually want to say
A server: The one who serves the request. [Servers are not allows to initialize a communications they only accepts connections and give services to requests]
A Client: The one who connects to server to gain some service and initialize connection with server
when you do socket programming on LAN as you are doing here it is pretty fine , any server can be hosted on any LAN computer and any client can initialize connection and can start communications, because they are in same home (for ease to say) They all know each other very well, but if you want to communicate some other computer which is outside the network then there are some issues,
Lets name [Computer A] who is in a LAN, and [Computer B] in same LAN.
[Computer C] is on a public IP address,
[Computer D] is also a computer in a LAN and that LAN is accessing Internet via router who uses a public IP Adress.
so if the Computer A is a Server and Computer B is a client then there is no issue they can communicate
if Computer D is a Client and "Computer C" is a Server then there is also not an issue as Client initiates a connection and spouses to be trusted and router know where to who initiates connections so where to send responses.
if Computer D is a Server then there is a issue, because Computer D has the Local Ip Address assigned by the router like 192.168...... and this ip is not presented to outside the word so no client can find the server so there cannot establish a connection, and that's what happening in your case
The only solution to accomplish this task is only one that (@Christiaan Rokowaski) mentioned that you should go to your router setting where the server resides and forward the packets to the port you are connect with on the local Ip where server resides like forward traffic to port [Local_IP:PORT_Number]
but what if you
don't have a physical access to router , mean you are developing a software to spread other non technical persons over the glob
so coming to that solution, well! sory to say but there is not a quite straight solution here, you have to search some terms and try out them, i have not tried any of them by myself so unfortunately i cannot refer some cod
there are some tricks that can be applied to achieved the solution
You can try ARP resolving, {not much sure about that)
AS your server resides behind the NAT you can study about it and one technical that is applied to do this is called
hole punching
which is i think not easy to implement the only successful implementation of this is
Skype
One easiest trick is (the one that most of messengers do) resides a server on a global IP and let all the clients connect to that server and do a mid man peer to peer communication
Quote:
some router allow to define dynamic port forwarding through UPNP, but it has to be enabled. That would be my recommended way if both sides are behind a NAT.
there are some useful links abut UPNP
Dot net port mapper
managed UpnP
finally this link is best explaining
Most Chat messengers use a server with a well known public IP to help clients communicate with each other. Each client communicates with the server and the server sends every message to the appropriate client. This is perhaps the only way to do it, because otherwise:
Every client should have a public IP in order for other clients to reach him. Each client should also act both as client and a server.
It will be very difficult to discover clients as you would need to know their IPs
a question posted similar to your problem