Results 1 to 3 of 3

Thread: can i use "winsock.connect" and "winsock.listen"?

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2008
    Posts
    1

    Unhappy can i use "winsock.connect" and "winsock.listen"?

    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..

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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.

  3. #3
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    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
  •  



Click Here to Expand Forum to Full Width