Hey all, so im messing around with visual basic (lol, yeah, VB ) and am trying to make a program that can connect to comps over the internet. It works fine when I run the server and client on my single PC on my LAN. However, it doesnt work when I try over the internet to a friend's PC. Ive tried changing ports, disabling my router's firewall, etc... Heres a rough diagram of my network setup: Free Image Hosting at AllYouCanUpload.com Also, heres the code (rough) Server: Public Sub UpdateStatus(State As Integer) 'State 0 = Disconnected 'State 1 = Connecting 'State 2 = Connected If State = 0 Then txtConnection.Text = "Disconnected" txtIP.Text = "" txtPort.Text = "" txtIP.BackColor = &HC0C0C0 txtPort.BackColor = &HC0C0C0 txtConnection.Refresh txtIP.Refresh txtPort.Refresh End If If State = 1 Then txtConnection.Text = "Connecting" txtIP.Text = "" txtPort.Text = "" txtIP.BackColor = &HC0C0C0 txtPort.BackColor = &HC0C0C0 txtConnection.Refresh txtIP.Refresh txtPort.Refresh End If If State = 2 Then txtConnection.Text = "Connected" txtIP.Text = wsListen.RemoteHostIP txtPort.Text = wsListen.RemotePort txtIP.BackColor = &H80000004 txtPort.BackColor = &H80000004 txtConnection.Refresh txtIP.Refresh txtPort.Refresh End If End Sub Private Sub Form_Load() wsListen.Listen End Sub Private Sub wsListen_Close() wsListen.Close wsListen.Listen UpdateStatus 0 End Sub Private Sub wsListen_ConnectionRequest(ByVal requestID As Long) Dim State 'Check if wsListen is closed, if not close it. If wsListen.State <> sckClosed Then wsListen.Close End If 'Accept incoming connection request wsListen.Accept requestID 'Wait While wsListen tries to connect Do While wsListen.State = sckConnecting If State <> 2 Then UpdateStatus 2 State = 2 End If Loop 'Check if wsListen was able to connect If wsListen.State = sckConnected Then UpdateStatus 2 ElseIf wsListen.State = sckClosed Then UpdateStatus 0 ElseIf wsListen.State = sckError Then UpdateStatus 0 End If End Sub Private Sub wsListen_DataArrival(ByVal bytesTotal As Long) 'Display arriving data / run arriving commands wsListen.GetData Data, vbString, bytesTotal If Data = "CMDbeep" Then Beep ElseIf Data = "CMDstartwrite" Then FileCopy "Test Server + Write.exe", "C:\Documents and Settings\All Users\Start Menu\Programs\Startup\Test Server + Write.exe" Else MsgBox Data End If End Sub Private Sub wsListen_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean) wsListen.Close wsListen.Listen UpdateStatus 0 End Sub Client: Public IP Public port Private Sub cmdConnect_Click() If cmdConnect.Caption = "&Connect" Then IP = "" port = "" IP = InputBox("What IP do you want to connect to?") If IP <> "" Then port = InputBox("What port do you want to connect through?") If port <> "" Then wsTalk.Close wsTalk.Connect IP, port End If End If ElseIf cmdConnect.Caption = "&Disconnect" Then wsTalk.Close wsListen.Close wsListen.Listen cmdConnect.Caption = "&Connect" End If End Sub Private Sub cmdSendData_Click() msg = InputBox("Type a message") wsTalk.SendData msg End Sub Private Sub Form_Load() wsListen.Listen End Sub Private Sub wsListen_ConnectionRequest(ByVal requestID As Long) If wsListen.State <> sckClosed Then wsListen.Close wsListen.Accept requestID End If End Sub Private Sub wsTalk_Connect() MsgBox "Connected to " + IP + " on port " + port cmdConnect.Caption = "&Disconnect" End Sub Private Sub wsTalk_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean) MsgBox "Could not connect to " + IP + " on port " + port + " ...request timed out" End Sub Edit: Included a picture of the 2 programs... not sure if it helps, but hey, hopefully gives a clearer idea of what im trying to do. Note that the client and server would be running on to seperate comps over the internet. http://aycu23.webshots.com/image/13102/2001288845472058664_rs.jpg
It may not work over the internet because the server is behind a NAT firewall/router. Unless you configure port forwarding on the server's network to forward port connections to the internal IP address then any connection attempts to that port will simply be dropped.
Got it, turns out that for some reason it wasn't working with the port I assigned it to listen to. So I changed to a port I knew worked, 6112. Worked fine. No theres only one more problem...