
June 12th, 2004, 08:20 AM
|
|
Contributing User
|
|
Join Date: May 2004
Location: East Side Verona, Southern Europe
Posts: 98
Time spent in forums: < 1 sec
Reputation Power: 5
|
|
|
howto connect 2 hosts with Winsock
I've tried my software with me like the server and I didn't receive the Connection Request from the client ...
the IP address used by the client is exact, I think there's something wrong with the ports ...
both server and client must use the same port number? Or need only 2 free ports, the number is indifferent?
my code:
Quote:
Private Sub cmdConnect_Click()
[...]
Select Case True
' Option1 is a switch between Server(0) and Client(1)
Case Option1(0).Value:
ws1.Close
ws1.LocalPort = 0
ws1.Listen
lblStato.Caption = "... listening ..."
lblStato.ForeColor = RGB(255, 100, 0)
Case Option1(1).Value:
ws1.Close
ws1.LocalPort = CInt(txtPort.Text)
ws1.Connect txtIP.Text, txtPort.Text
lblStato.Caption = "... connecting ..."
lblStato.ForeColor = RGB(255, 100, 0)
End Select
[...]
End Sub
Private Sub ws1_Connect()
lblStato.Caption = "Connected"
lblStato.ForeColor = RGB(0, 255, 0)
connesso = True
cmdConnetti.Picture = il2.ListImages(2).Picture
cmdConnetti.Caption = "Disconnect"
txtUtente.Enabled = False
txtFrase.Enabled = True
End Sub
'this sub is 4 the server when the request is arrived
Private Sub ws1_ConnectionRequest(ByVal requestID As Long)
If ws1.State <> sckClosed Then ws1.Close
ws1.Accept requestID
lblStato.Caption = "Connected"
lblStato.ForeColor = RGB(0, 255, 0)
connesso = True
cmdConnetti.Picture = il2.ListImages(2).Picture
cmdConnetti.Caption = "Disconnect"
txtUtente.Enabled = False
txtFrase.Enabled = True
End Sub
Private Sub ws1_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 Description, vbOKOnly + vbCritical, "Error " + CStr(Number)
End Sub | Thx 
|