Click here to Skip to main content
15,911,711 members
Please Sign up or sign in to vote.
1.00/5 (2 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 (connected with Internet)

Client:(IP > 72.55.168.241)
C#
private void ConnectionRemoteEndPoint()
        {
            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);
            }
           
        }

other Remote Computer (e.g here Server)IP is 192.168.1.3(Local LAN Ip) connected with Internet.

Server: (IP > 192.168.1.3)
C#
private void AcceptRemoteEndPoint()
{
      TcpListener listener_tcp;
      TcpClient Remtcp;
      listener_tcp = new TcpListener(IPAddress.Parse(192.168.1.3), 2000);
      listener_tcp.Start();
            while (true)
            {
                Remtcp = listener_tcp.AcceptTcpClient();
            }
}

Error come from ConnectionRemoteEndPoint() function:
Error: A request to send or receive data was disallowed because the socket is not connected and ( when sending on datagram socket using sendto call)and no address was supplied.

Please Help..
thanks.
Posted
Updated 31-Jan-11 23:19pm
v2

You can not connect Local LAN IP for server through internet by socket. You wrote 192.168.1.3(Local LAN Ip). For server you need a real IP if you want to use socket through internet.
 
Share this answer
 
v2
Comments
sufi2008123 1-Feb-11 5:36am    
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 Inter IP using tools like (whatsmyip.com etc). Here the communication issue arises. Any help will be highly appreciated.
Sergey Alexandrovich Kryukov 1-Feb-11 15:19pm    
This is a duplicate question -- not good.
Please see my answer.
--SA
See my answer here:

Problem to connect using Socket [^].

Now, please tell me, why this question is nearly identical to that?!
You should not do that.

—SA
 
Share this answer
 
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
 
Comments
Sergey Alexandrovich Kryukov 1-Feb-11 15:19pm    
This is a duplicate question -- not good.
Please see my answer.
--SA
This is a problem related to NAT Mapping. Since different firewalls also provide the restriction, we need to punch holes.

Still no luck :((
 
Share this answer
 
v2

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