出错症状:服务端显对话框"已连接",然后输入消息 点发送。就说出错了 错误代码40006
所需事物或请求的错误协议或请求状态
客户端:点了连接就没反应了。
代码:服务端:
Private Sub Command1_Click()
Me.Command1.Enabled = False
Me.Winsock1.Listen
End Sub
Private Sub Command2_Click()
Dim STR As String
STR = Me.Text2.Text & ":" & Me.Text1.Text
Me.List1.List(Number) = STR
Number = Number + 1
Me.Winsock1.SendData STR
Me.Text1.Text = ""
End Sub
Private Sub Command3_Click()
Dim Objects As Object, Strings As String
Set Objects = CreateObject("Microsoft.XMLHTTP")
Objects.Open "GET", "http://www.ip138.com/ip2city.asp", False
Objects.Send
If Objects.ReadyState = 4 Then
Strings = StrConv(Objects.Responsebody, vbUnicode)
End If
If InStr(Strings, "[") > 0 And InStr(Strings, "]") > 0 Then
MsgBox "您外网的IP地址是:" & Split(Split(Strings, "[")(1), "]")(0), vbInformation, "聊天器服务端"
Else
MsgBox "外网IP地址获取失败!", vbCritical, "聊天器服务端"
End If
End Sub
Private Sub Form_Load()
Number = 0
End Sub
Private Sub Timer1_Timer()
If Me.Winsock1.State = 8 Then
MsgBox "连接断开。", vbInformation, "聊天器服务端"
Me.Command1.Enabled = True
Me.Command2.Enabled = False
Me.Text2.Enabled = True
Me.Timer1.Enabled = False
Me.Winsock1.Close
End If
End Sub
Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
If Me.Winsock1.State <> sckClosed Then
Me.Winsock1.Close
End If
Me.Winsock1.Accept requestID
MsgBox "已连接!", vbInformation, "聊天器服务端"
Me.Timer1.Enabled = True
Me.Command2.Enabled = True
Me.Text2.Enabled = False
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim Information As String
Me.Winsock1.GetData Information
Me.List1.List(Number) = Information
Number = Number + 1
End Sub
客户端;
Private Sub Command1_Click()
Dim STR As String
STR = "客服端:" & Me.Text1.Text
Me.List1.List(Number) = STR
Number = Number + 1
Me.Winsock1.SendData STR
Me.Text1.Text = ""
End Sub
Private Sub Command2_Click()
Me.Command2.Enabled = False
Me.Text2.Enabled = False
Me.Winsock1.RemoteHost = Me.Text2.Text
Me.Winsock1.Connect
Me.Timer1.Enabled = True
End Sub
Private Sub Form_Load()
Number = 0
End Sub
Private Sub Timer1_Timer()
If Me.Winsock1.State = 0 Then
Me.Winsock1.Connect
End If
If Me.Winsock1.State = 9 Then
Me.Winsock1.Close
End If
If Me.Winsock1.State = 6 Then
Me.Command2.Caption = "正在连接..."
End If
End Sub
Private Sub Timer2_Timer()
If Me.Winsock1.State = 8 Then
MsgBox "连接断开。", vbInformation, "聊天器客户端"
Me.Command1.Enabled = False
Me.Command2.Enabled = True
Me.Text2.Enabled = True
Me.Timer2.Enabled = False
Me.Winsock1.Close
End If
End Sub
Private Sub Winsock1_Connect()
Me.Command2.Caption = "已连接"
Me.Timer1.Enabled = False
Me.Timer2.Enabled = True
Me.Command1.Enabled = True
MsgBox "已连接!", vbInformation, "聊天器客户端"
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim Information As String
Me.Winsock1.GetData Information
Me.List1.List(Number) = Information
Number = Number + 1
End Sub
难道你每一次发送消息都用Winsock连接了一次????
请给出报的错误信息 或者把源码贴出来!!