vb winsock 实时错误“40006” 所需事物请求的错误协议连接或连接状态。我检查了好几遍不知道怎么错了。

PrivateSubCommand1_Click()Winsock2.ConnectEndSubPrivateSubCommand2_Click()Winsock1.Se... Private Sub Command1_Click()
Winsock2.Connect
End Sub

Private Sub Command2_Click()
Winsock1.SendData "ok"

End Sub

Private Sub Form_Load()

Winsock1.LocalPort = 12345
Winsock1.Listen

Winsock2.RemoteHost = "127.0.0.1"
Winsock2.RemotePort = 12345

End Sub

Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
MsgBox " clent connect "

End Sub

Private Sub Winsock2_DataArrival(ByVal bytesTotal As Long)
MsgBox " receive data"
End Sub

Private Sub Winsock2_Connect()
MsgBox "ok"

End Sub
展开
 我来答
赚钱啊呀
2011-04-24 · TA获得超过218个赞
知道小有建树答主
回答量:99
采纳率:0%
帮助的人:97.3万
展开全部
winsock1充当服务器的角色,你不在winsock1的ConnectionRequestion事件中调用accept方法,当然会出错,只有调用accept方法,winsock1(服务器)才会接受winsock2(客户端)的连接请求。
tianqing20wen

推荐于2017-09-21 · TA获得超过2.4万个赞
知道大有可为答主
回答量:8226
采纳率:88%
帮助的人:5009万
展开全部
Private Sub Command1_Click()
Winsock2.Connect
End Sub

Private Sub Command2_Click()
Winsock2.SendData "ok"
End Sub

Private Sub Form_Load()
Winsock1.LocalPort = 12345
Winsock1.Listen

Winsock2.RemoteHost = "127.0.0.1"
Winsock2.RemotePort = 12345
End Sub

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

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim a As String
Winsock1.GetData a
msgbox a
End Sub

Private Sub Winsock2_Connect()
MsgBox "ok"
End Sub
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式