用winsock控件
Private Sub Command3_Click()
If SockCL.State <> 0 Then
SockCL.Close
End If
SockCL.RemoteHost = "192.168.0.21"
' 指定服务器端口名
SockCL.RemotePort = 8000
' 连接到服务器
SockCL.Connect
End Sub
Private Sub Form_Load()
' 指定服务器主机名
If SockCL.State <> 0 Then
SockCL.Close
End If
SockCL.RemoteHost = "192.168.0.21"
' 指定服务器端口名
SockCL.RemotePort = 8000
' 连接到服务器
SockCL.Connect
' If SockCL.State = 7 Then
' MsgBox "hehe", vbCritical + vbApplicationModal
' Else
' MsgBox "heeh"
' End If
End Sub
Private Sub SockCl_DataArrival(ByVal bytesTotal As Long)
Dim DataStr As String
' 接收数据到文本框中
SockCL.GetData DataStr
Debug.Print SockCL.State
Text2.Text = DataStr
End Sub
' 向服务器发送数据
Private Sub Command1_Click()
If SockCL.State = 7 Then
SockCL.SendData Text1.Text
End If
End Sub
' 退出程序
Private Sub Command2_Click()
SockCL.Close
End
End Sub