|
-
Jun 20th, 2008, 10:53 AM
#1
Thread Starter
New Member
-
Jun 20th, 2008, 12:09 PM
#2
Re: can i use "winsock.connect" and "winsock.listen"?
Welcome to the forums. 
I'm afraid I don't get what you mean. Could you supply more details please?
Also, if you have some code that isn't doing what you need it to do, then please post it so we can take a look.
-
Jun 24th, 2008, 01:13 AM
#3
Re: can i use "winsock.connect" and "winsock.listen"?
The Winsock.Listen method is normally used by a 'Server' which is expecting connection requests from a 'Client'. The Winsock.Connect method is used by the 'Client' to request connection to the 'Server'. So, that means that a particular Winsock is either Listening or Connecting - not both. You can have, say, 2 Winsocks on a Form, one Listening for connections and the other requesting a connection.
eg
Code:
Private Sub cmdConnect_Click()
'
' Winsock2 is the 'Client'
' Request connection to the 'Server'
'
Winsock2.RemoteHost = "localhost"
Winsock2.RemotePort = 4001
Winsock2.Connect
End Sub
Private Sub Form_Load()
'
' Winsock1 is the 'Server' Listening on Port 4001
' for Connection Requests
'
Winsock1.LocalPort = 4001
Winsock1.Listen
End Sub
Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
'
' 'Server' has received a Connection Request
' Stop it from Listening and accept the Connection Request
'
Winsock1.Close
Winsock1.Accept requestID
End Sub
Private Sub Winsock2_Connect()
'
' The 'Server' has accepted the Connection Request
' Display a MessageBox showing the IP address of the 'Server'
' and Port number
'
MsgBox "Winsock2 has successfully connected to " & Winsock2.RemoteHostIP & " on Port " & Winsock2.RemotePort
End Sub
Last edited by Doogle; Jun 24th, 2008 at 01:18 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|