Winsock Control in VB6

From Free Knowledge Base- The DUCK Project: information for everyone
Jump to: navigation, search

Code Sample:

 tcpClient.RemotePort = 110

 tcpClient.Protocol = sckTCPProtocol

 tcpClient.RemoteHost = txtPop.Text  <-- can be an IP address

 tcpClient.Connect

 tcpClient.GetData strStream

 txtOut.Text = txtOut.Text & strStream

 If tcpClient.State = 7 Then

 Sub tcpClient_DataArrival(ByVal bytesTotal As Long)
     Dim strData As String, strText As String
     tcpClient.GetData strData: Debug.Print "->" & strData
 End Sub

 Dim strOut As String
 strOut = tcpClient.State
 Constant              Value Description 

 sckClosed             0 Default. Closed
 sckOpen               1 Open
 sckListening          2 Listening
 sckConnectionPending          3 Connection pending
 sckResolvingHost      4 Resolving host 
 sckHostResolved       5 Host resolved 
 sckConnecting                 6 Connecting
 sckConnected                  7 Connected
 sckClosing            8 Peer is closing the connection
 sckError              9 Error

 Private Function txtConnectionState(x)
   Select Case x
   Case 0
     txtConnectionState = "Default Closed"
   Case 1
     txtConnectionState = "Open"
   Case 2
     txtConnectionState = "Listening"
   Case 3
     txtConnectionState = "Connection Pending"
   Case 4
     txtConnectionState = "Resolving Host"
   Case 5
     txtConnectionState = "Host resolved"
   Case 6
     txtConnectionState = "Connecting"
   Case 7
     txtConnectionState = "Connected"
   Case 8
     txtConnectionState = "Peer is closing the connection"
   Case 9
     txtConnectionState = "Error"
   End Select
 End Function

 tcpClient.SendData (strMessage)

 tcpClient.SendData ("user " & txtUser.Text & vbCrLf)
 tcpClient.SendData ("pass " & txtPass.Text)