vb winsock控件实时错误40006 求助

server:PrivateSubForm_Load()DimPortAsIntegerPort=InputBox("IP(Frm1)","","2008")Winsoc... server:

Private Sub Form_Load()
Dim Port As Integer
Port = InputBox("IP(Frm1)", "", "2008")
Winsock1.RemotePort = Port
Winsock1.Listen
End Sub

Private Sub Timer1_Timer()
Label1 = Winsock1.State
End Sub

Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
If Winsock1 <> 0 Then: Winsock1.Close
Winsock1.Accept requestID
End Sub

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim DData As String
Winsock1.GetData DData
Text1 = DData
End Sub

Client:

Private Sub Command1_Click()
Winsock1.Connect
End Sub

Private Sub Form_Load()
Dim IP As String
Dim Port As Integer
IP = InputBox("IP(Frm2)", "", "127.0.0.1")
Port = InputBox("Port", "", "2008")
Winsock1.RemoteHost = IP
Winsock1.RemotePort = Port

End Sub

Private Sub Text1_Change()
Winsock1.SendData Text1
End Sub

Private Sub Timer1_Timer()
Label1 = Winsock1.State
End Sub

经测试:服务端(Frm1.winsock1.state=2)
客户端(Frm1.winsock1.state=9)
孤星逐梦
我SERVER那边的winsock1.listen

还有过程Winsock1_ConnectionRequest里的意思是如果客户连接时没关闭连接, _
那么关闭连接,这样有错吗?

如果改的话应该怎么改?谢谢
展开
 我来答
孤星逐梦
2008-10-27 · TA获得超过257个赞
知道小有建树答主
回答量:356
采纳率:0%
帮助的人:0
展开全部
Client:
Private Sub Command1_Click()
Winsock1.Connect
End Sub

Private Sub Form_Load()
Form2.Show
Dim IP As String
Dim Port As Integer
IP = InputBox("IP(Frm2)", "", "127.0.0.1")
Port = InputBox("Port", "", "2008")
Winsock1.RemoteHost = IP
Winsock1.RemotePort = Port

End Sub

Private Sub Text1_Change()
Winsock1.SendData Text1
End Sub

Private Sub Timer1_Timer()
Label1 = Winsock1.State
End Sub

server:

Private Sub Form_Load()
Dim Port As Integer
Port = InputBox("IP(Frm1)", "", "2008")
Winsock1.LocalPort = Port '''这里是监听而不是连接
Winsock1.Listen
End Sub

Private Sub Timer1_Timer()
Label1 = Winsock1.State
End Sub

Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
If Winsock1.State <> 0 Then: Winsock1.Close '''这里要写状态的
Winsock1.Accept requestID
End Sub

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim DData As String
Winsock1.GetData DData
Text1 = DData
End Sub
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式