| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 542 人关注过本帖
标题:谁帮我看看这个 winsock 为什么无法连接
只看楼主 加入收藏
zhuiis
Rank: 4
等 级:业余侠客
威 望:1
帖 子:201
专家分:286
注 册:2008-11-8
结帖率:82.14%
收藏
已结贴  问题点数:20 回复次数:1 
谁帮我看看这个 winsock 为什么无法连接
这个连接总是出现“40020错误,当前状态的操作无效”
Winsock.zip (2.65 KB)

请大家帮我看看,这到底是怎么回事!谢谢了!

Private Sub Command1_Click()
Command1.Enabled = False
Winsock2.RemoteHost = "192.168.1.101"
Winsock2.RemotePort = 1001
Winsock2.Connect "192.168.1.101"
End Sub

Private Sub Command2_Click()
Winsock2.SendData Text2.Text
End Sub

Private Sub Form_Load()
Winsock1.LocalPort = 1001
Winsock1.Listen
End Sub

Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
Winsock1.Accept requestID
End Sub

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

Private Sub Winsock2_Connect()
Command2.Enabled = True
End Sub

Private Sub Winsock2_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
Command1.Enabled = True
Command2.Enabled = False
End Sub
2011-05-24 22:38
风吹过b
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:364
帖 子:4947
专家分:30084
注 册:2008-10-15
收藏
得分:20 
Private Sub Command1_Click()
Command1.Enabled = False
Winsock2.RemoteHost = "192.168.1.101"
Winsock2.RemotePort = 1001
Winsock2.Connect             '已指定IP和端口,就不再需要带参数了
'"192.168.1.101"
End Sub

Private Sub Command2_Click()
Winsock2.SendData Text2.Text
End Sub

Private Sub Form_Load()
Winsock1.LocalPort = 1001
Winsock1.Listen
End Sub

Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
Winsock1.Close               'Winsock1 处于 侦听状态,如果你需要使用它来接收受连接,就必须先关闭
Winsock1.Accept requestID
End Sub

授人于鱼,不如授人于渔
早已停用QQ了
2011-05-25 07:49
快速回复:谁帮我看看这个 winsock 为什么无法连接
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019492 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved