Click here to Skip to main content
15,911,531 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
One Remote Computer (eg. here Client) has Static Ip Like 72.55.168.241 want to connect other Remote Computer has LAN Ip like 192.168.1.3(connect to Internet by Router)

Client:
private void ConnectRemoteEndPoint()
        {
            IPAddress ipAddr;
            TcpClient tcpServer=new TcpClient();
            ipAddr = IPAddress.Parse("192.168.1.3")
            try
            {
                tcpServer.Connect(ipAddr, 2000);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
            }
        }

other Remote Computer (e.g here Server)IP is 192.168.1.3(LAN Ip) connect to Internet by Router..

Server:
private void AcceptRemoteEndPoint()
{
      TcpListener listener_tcp;
      TcpClient tcp_Remote;
      listener_tcp = new TcpListener(IPAddress.Parse("192.168.1.3"), 2000);
      listener_tcp.Start();
            while (true)
            {
                tcp_Remote= listener_tcp.AcceptTcpClient();
            }
)

This code is not working Properly.
Please Help.
thanks


[Edited]Code is blocked in "pre" tags[/Edited]
Posted
Updated 31-Jan-11 21:22pm
v2
Comments
Prerak Patel 1-Feb-11 3:23am    
You may like to specify what error you get.

1 solution

sounds like you need to configure your router to accept incoming TCP connections on port 2000 and forward them to 192.168.1.3. you'll also need to change the IP address in your code to that of the external interface of the router.
 
Share this answer
 
v2
Comments
sufi2008123 1-Feb-11 5:40am    
So, you mean to say that every time you use Yahoo messenger, GTalk, Skype etc., you have to configure the Router. Hey Jim the problem is something else.

To clarify he above posted question: Both machines communicate using a socket server over the Internet. Although the machines have unique IP in the LAN, but the main problem is that, both the machines have same IP on the Internet. And Sockets communicate only through IP and PORT, so how will we distinguish which machine is requesting what??? Note, I am taking about the problem, only when communicating over the Internet, and you can find each machines Internet IP using tools like (whatsmyip.com etc). Here the communication issue arises. Any help will be highly appreciated.
jim lahey 1-Feb-11 5:45am    
no sufi, I don't mean that every time you use a chat client you have to configure your router, and I never said that.

you did say, however, that your client has a public IP and is trying to connect to the server on your LAN. for this to work, you have to get your request forwarded from your LAN's router's external interface to the private IP (192.168.1.3) of your server.

http://portforward.com/help/portforwarding.htm

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900