Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Winsock over the internet

Status
Not open for further replies.

zemp

Programmer
Jan 27, 2002
3,301
CA
I am trying to get two apps to work together. One that will send a message, using winsock, from one IP address to another. And a second that listens for the message, using winsock, and records it in a file. I have this setup working across our network (Intranet) but I can't get it to work over the internet.

I guess I have a couple of questions. First is Winsock the right tool for the job? If not what is? If it is the right tool, what do I need to do to make it work over the internet.

I am not getting any errors, just that the connection failed. Below is the code that I am using and both apps winsock controls are listening to the same port.

If Winsock1.State = sckConnected Then Winsock1.Close
Winsock1.RemoteHost = m_strIPAddress
Winsock1.RemotePort = 1001
Winsock1.Connect

Do Until Winsock1.State = sckConnected
DoEvents: DoEvents: DoEvents: DoEvents
If Winsock1.State = sckError Then
Msgbox "Connection failed!"
Winsock1.Close
Exit Sub
End If
Loop

Winsock1.SendData txtMessage.Text
Thanks and Good Luck!

zemp
 
Yes winsock is good to do the job but i think the problem is in the first part of code correct me if i'm wrong, If Winsock1.State = sckConnected Then Winsock1.Close if im right when winsock is connected u close it again..?? maybe thats the problem otherwise u schould check if ports and ip adresses missmatch..

give it a try, good luck

Greetings,

ThaVolt
 
Thanks for the quick response. Ports and IPAdresses that work within our network are not changed when I take the client app out of our network and try over the internet.

The first line,

If Winsock1.State = sckConnected Then Winsock1.Close

is suppose to close any open connections before winsock tries to connect to the server app again. This is straight out of tutorial sites. I am a Winsock newbie. I'll try your suggestion. Thanks and Good Luck!

zemp
 
I'd leave the first statement in there. That's supposed to take place before you try to establish your connection. As you said, it's just a safety to make sure Winsock1 is ready to initiate a connection.

How do the two machines find each other on the internet? Is your server connected directly to the internet with a static IP? The reason I ask is, I assume your intranet uses a gateway when it connects to the internet. The gateway would need to be configured to direct this traffic to your server. You could tell the gateway that any incoming connections to port ##### should go to your server. Better yet, use a VPN to essentially put your client (the one trying to establish the connection) inside your intranet.
 
I should note that if you try my first solution, your client should attempt to connect to the gateway (using the gateway's IP) which would then redirect the traffic to the server. Your internal IP addresses probably fall within the range of private addresses which means that traffic using those addresses will not be able to traverse the internet. Even if they're public addresses, it's very unlikely that each host inside your intranet has direct internet access, i.e. they're not visible from the internet.

The VPN is far better. For one thing, you wouldn't have to change anything within your server and client apps. Once the VPN is established, it's as though the client is sitting right inside your intranet. For another thing, for security, the fewer ports you can have open to the internet the better off you'll be.
 
Thanks Schroeder, your response makes sense. I will look into the VPN tromorrow and hopefully I will be able to move forward.

Thanks and Good Luck!

zemp
 
This is a really old thread, but since Im having the same problem, Id like to ressurect it...

The IP adds match up, ports are good. everything in my app works fine....if in using it on my LAN, but as soon as I try to have a friend of mine connect to me over an internet connection rather than from a local LAN based machine....it no workie.....he still connects, I know because I have a "Status form" that tells me when people are connected and on which winsock control, but no data is passed between the computers...i.e.: we cant chat. (and no, this isnt just a chat program, the chat is just the feature im choosing to test connectivity with cause it was easiest to implement).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top