PDA

Click to See Complete Forum and Search --> : can i use "winsock.connect" and "winsock.listen"?


melvinace14
Jun 20th, 2008, 10:53 AM
can i use "winsock.connect" and "winsock.listen"? can i use both of them in one form or project??.,


i have a problem to send command in client side.., i cannot hide the form1 and show the form2?? do you get what i mean??., plz help me now.. im making a thesis right now.. :( :(

Hack
Jun 20th, 2008, 12:09 PM
Welcome to the forums. :wave:

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.

Doogle
Jun 24th, 2008, 01:13 AM
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

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