PDA

Click to See Complete Forum and Search --> : Another Winsock Problem :)


Dec 11th, 1999, 07:01 PM
Ok, Iming writeing a client/server thing. For some reason It only works on my computer. It a send someone else the server and try to connect over the internet it doesnt work.

Here is the basic connection part of the program:

CLIENT

Private Sub Command1_Click()
On Error GoTo error
'Close old connections
Winsock1.Close
' connect
Winsock1.Connect Text1.Text, 5678
Command1.Enabled = False 'disable connect command button
Command2.Enabled = True 'enable diconect command button

error:
Exit Sub
End Sub


SERVER

Private Sub Form_Load()
MakeProgramStealth
' here it listen for connection to port 5678
Winsock1.LocalPort = 5678
Winsock1.Listen
End Sub

Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
' it's accept connection when anything asks
If Winsock1.State <> sckClosed Then Winsock1.Close
Winsock1.Accept requestID
End Sub

IF someone could find why this connects when both are on my computer and not over the internet I would greatly appreciate it.

Thanks

vbsquare
Dec 12th, 1999, 02:16 AM
What are you typing into text1?

------------------
"To the glory of God!"

Dec 12th, 1999, 02:19 AM
You have to know the IP and Port of the listening server. Your port 5678 is probably ok, but are you certain about the IP ? Some IP's are dynamically assigned and therefore will vary each time you start your internet connection.
I had my server publish the current IP and Port to a web page, then the client would get the info from that page and connect to the current IP and Port.
Or you can try to connect to a range of IP's with the same port. Your app should be the only one that responds (if it really isn't being used) to a valid combination.

Dec 12th, 1999, 05:57 AM
Text1.text is a ip address

Dec 12th, 1999, 07:19 AM
Yes, but are you certain that it is a valid IP address NOW? Read the part about dynamically assigned again.

Dec 12th, 1999, 04:32 PM
Make sure you aint useing your own ip or 127.0.0.1localhost.

Also try checking(?) if there aren't any errors

Private Sub Winsock1_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 "Woepsie: " & Description, vbOKOnly + vbCritical, "Error!!!!!!!!"
End Sub


you could also check the state of the winsock.


Private Sub Command1_Click()
On Error GoTo Error
'Close old connections
Winsock1.Close

'Connect
Winsock1.Connect Text1.Text, 5678

'Wait for connection, but abort if there is an error
Do Until Winsock1.State = sckConnected And Not Winsock1.State = sckError
DoEvents
Loop
If Winsock1.State = sckError Then
MsgBox "Error occurd while trying to connect to " & Text1
End If

Command1.Enabled = Not (Winsock1.State = sckConnected) 'disable connect command button
Command2.Enabled = (Winsock1.State = sckConnected) 'enable disconnect command button
Error:
Exit Sub
End Sub


------------------

Vincent van den Braken
EMail: azzmodan@azzmodan.demon.nl
ICQ: 15440110 (http://www.icq.com/15440110)
Homepage: http://www.azzmodan.demon.nl