0
votes

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).

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? If yes, can you please guide me or link a tutorial so that my application does this automatically or is there an alternative approach to achieve this and so that port forward is not required? Thanks a lot!

1
If you're connecting over internet, port forwarding IS a must, like for all network connections, so the appropriate machine responds to the appropriate port. When connecting on a LAN, you just need to allow outgoing on the client and incoming connections on the server on the firewall. There is no way your program can setup those, it's completely outside of your app responsibilities to do so. You should put clear documentation or guidelines for the user to perform those steps on both PCs. A "test connection" button may help for troubleshooting. - Alejandro
thanks for the help Alejandro!, i have a question though - how do application like utorrent and teamviewer work? They never ask user to port forward... - Mohit
Teamviewer makes only outgoing connections from both sides, and their server manages the connection, so they don't require port forwarding (but DOES need outgoing firewall permissions on the port it uses). UTorrent does needs port forwarding on your side in fact, and it offers a test for that, because being a peer-to-peer protocol, it listens for connections for seeding, and while it may work without it, it just lets you download, making Bittorrent inneficient. The only thing I think you can do to avoid port forwarding from the users is to host the server part yourself. - Alejandro
ok - you explained it very well Alejandro! Thanks a lot buddy! Ok so if i make one of my systems - always available and port-forward just on this system, i can redirect traffic b/w different clients, right? and yes - how can i plus rep you? (or make this a valid answer?) - Mohit

1 Answers

0
votes

You say the other machine has an external ip address. This implies it also has a local ip address; ie it is behind a NAT firewall or similar. In this case, you will have to configure the firewall to allow communication to take place, eg by setting up port forwarding. Applications such as MSN Messenger, VOIP clients etc have elaborate mechanisms to negotiate this automatically, but they're often not very successful.