这是一个简单的服务端和客户端程序,不知道发生什么错误
1.服务端程序
Dim sendmsg As String
Private Sub Form_Load()
Winsock1.LocalPort = 20000
Winsock1.Listen
Text1.Locked = True
End Sub
Private Sub winsock1_connectionrequest(ByVal requestid As Long)
If Winsock1.State <> sckClosed Then Winsock1.Close
Winsock1.Accept requestid
sendmsg = "收到信息没有"
Winsock1.SendData sendmsg
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim s As String
Winsock1.GetData s
If Text1.Text = "" Then
Text1.Text = "信息:" & s
Else
Text1.Text = ""
Text1.Text = "信息:" & s
End If
End Sub
Private Sub command1_click()
sendmsg = Text2.Text
Winsock1.SendData sendmsg
End Sub
Private Sub winsock1_sendcomplete()
If Text1.Text = "" Then
Text1.Text = "信息已发送" & sendmsg
Else
Text1.Text = Text1.Text & "信息已发送" & senmsg
End If
End Sub
Private Sub command2_ckick()
Winsock1.Close
End
End Sub
Private Sub form_unload(cancel As Integer)
Winsock1.Close
End Sub
2.客户端程序
Dim sendmsg As String
Private Sub Form_Load()
sockcl.RemoteHost = "192.168.13.1"
sockcl.RemotePort = 2000
sockcl.Connect
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim datastr As String
sockcl.GetData datastr
If Text1.Text = "" Then
Text1.Text = "from server:" & datastr
Else
Text1.Text = ""
Text1.Text = "from server:" & datastr
End If
End Sub
Private Sub Command1_Click()
sendmsg = Text2.Text
sockcl.SendData sendmsg
End Sub
Private Sub Winsock1_SendComplete()
If Text1.Text = "" Then
Text1.Text "to server:" & sendmsg
Else
Text1.Text = Text1.Text & "发送完成" & sendmsg
End If
End Sub
Private Sub Command2_Click()
sockcl.Close
End
End Sub