Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have created a simple tcp client-server application in vb.net. Everything works fine when i set local host (127.0.0.1) as the ip address. I wish to make a connection to a remote machine (keeping client at my machine and server on the other - or vice versa).

How can i connect to the remote machine if i have its external ip address? I have tried searching on the internet but couldn't clarify this. Thanks a lot!

EDIT:

ok, the code of interest is as follows:

the server:


Dim server As TcpListener = New TcpListener(IPAddress.Any, port)

the client:

Dim theip As IPAddress = IPAddress.Parse(TextBox1.Text)
client = New TcpClient(theip.ToString, port)

Now, what should i enter in "TextBox1.Text" if i have my client on a remote machine (connected over internet) and server at a different computer (whose external IP address is known)?
Can i enter the external IP address of the machine running the server directly in the text box? Also, do i need to take care of things like "port forwarding" / "let firewall allow the connection" and all?
Posted
Updated 14-Jul-13 5:29am
v4
Comments
[no name] 14-Jul-13 11:19am    
I am not sure that I understand what it is that you are asking, "what should i enter in", you would enter the IP address of the computer that you are trying to connect to.....
mohit7 14-Jul-13 11:22am    
that's what i need to know - can i enter the external IP directly there? And do i need to do any sort of "port forwarding" / firewall stuff? or will this work directly?
[no name] 14-Jul-13 12:05pm    
And how would you expect someone that does not know anything about how your computers are setup to know that?
mohit7 14-Jul-13 12:18pm    
buddy am just experimenting things - this is not a product for someone - am actually trying to learn about client / server interaction - i have always worked on localhost and am just trying to implement this on two separate remote machines, please help me out...
[no name] 14-Jul-13 12:40pm    
Okay and... so? Help you with what exactly? Port forwarding? Sure go do that if you need to. Opening ports in your firewall? Sure go do that if you need to. The thing you apparently do not understand is the people here are probably half way around the world from you and we would have exactly no idea how your computers are setup, how your network is setup or anything else.

1 solution

See:

socket-bind-returns-the-requested-address-is-not-valid-in-its-context-on-wi[^]
tcpclient-exception-requested-address-not-valid-its-context-t[^]

[This error usually results from an attempt to bind a listening socket to an IP address that's not valid for the local machine.]

Of course you have to allow the connection via the firewall (in case it is set to block such a connection), other wise the firewall will be pretty much useless.

Cheers,
Edo
 
Share this answer
 
v3
Comments
mohit7 14-Jul-13 10:32am    
thanks a lot for the help Edo, so what IP should i assign to the listener if i wish to listen from a remote machine? Also, what IP should be assigned to the TcpClient in this case?
Joezer BH 14-Jul-13 10:55am    
Can you show relevant code (you can edit the question itself and add it there)
Basically what I suggested is that you make sure that the address you use be valid on the local machine.
mohit7 14-Jul-13 11:11am    
I have edited the question buddy, and for the server i have set the address to "IPAddress.Any". What should i set the address for the client to?
Joezer BH 15-Jul-13 2:18am    
In the following example the value in TextBox1.Text should be a valid address on the client machine.

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