跟据书写的,用WINSOCK作了一个程序,但真实联机里却联下上,显示的是10060
我PING我那个同学的IP也PING不同
------------------------------------------------
Dim reqid As Long ''定义用于保存请求ID的变量
Dim st As String ''定义用于保存接收到数据的变量
Private Sub Command1_Click() ''监听按钮事件
ws1.LocalPort = Text2.Text
ws1.Bind Text2.Text, Text1.Text ''绑定端口
ws1.Listen
End SubPrivate Sub Command2_Click()
Select Case Command2.Caption
Case "连接"
If ws1.State <> sckClosed Then ws1.Close ''检测一下控件状态,这一点很重要,不然会产生40020错误
ws1.RemoteHost = Text3.Text
ws1.RemotePort = Text4.Text
ws1.Connect
Text2.Text = ws1.LocalPort
Case "断开"
ws1.Close
End Select
End SubPrivate Sub Command3_Click()
ws1.SendData Text6.Text ''发送信息
End SubPrivate Sub Form_Load()
Text1.Text = ws1.LocalIP ''在程序运行初期得到本机IP,并在TEXT1内显示
ws1.Protocol = sckTCPProtocol ''设置程序使用协议
End SubPrivate Sub Timer1_Timer()
Select Case ws1.State
Case 0
Label2.Caption = "连接状态为:已关闭"
Command2.Caption = "连接"
Case 1
Label2.Caption = "连接状态为: 打开 "
Case 2
Label2.Caption = "连接状态为:监听"
Case 3
Label2.Caption = "连接状态为:连接挂起"
Case 4
Label2.Caption = "连接状态为:识别主机 "
Case 5
Label2.Caption = "连接状态为:已识别主机"
Case 6
Label2.Caption = "连接状态为:正在连接"
Case 7
Label2.Caption = "连接状态为:已连接"
Command2.Caption = "断开"
Case 8
Label2.Caption = "连接状态为:同级人员正在关闭连接"
Case 9
Label2.Caption = "连接状态为:错误"
End Select
End SubPrivate Sub ws1_ConnectionRequest(ByVal requestID As Long)
Dim bool As Integer
bool = MsgBox("发现连接请求!", vbOKCancel)
If bool = 1 Then
Command2.Caption = "断开"
If ws1.State <> 0 Then
ws1.Close
ws1.Accept requestID
Text2.Text = ws1.LocalPort
Text3.Text = ws1.RemoteHostIP
Text4.Text = ws1.RemotePort
End If
Else
ws1.Close
End If
End SubPrivate Sub ws1_DataArrival(ByVal bytesTotal As Long)
ws1.GetData st
Text5.Text = st
End SubPrivate Sub ws1_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)
MsgBox Number
End Sub
我PING我那个同学的IP也PING不同
------------------------------------------------
Dim reqid As Long ''定义用于保存请求ID的变量
Dim st As String ''定义用于保存接收到数据的变量
Private Sub Command1_Click() ''监听按钮事件
ws1.LocalPort = Text2.Text
ws1.Bind Text2.Text, Text1.Text ''绑定端口
ws1.Listen
End SubPrivate Sub Command2_Click()
Select Case Command2.Caption
Case "连接"
If ws1.State <> sckClosed Then ws1.Close ''检测一下控件状态,这一点很重要,不然会产生40020错误
ws1.RemoteHost = Text3.Text
ws1.RemotePort = Text4.Text
ws1.Connect
Text2.Text = ws1.LocalPort
Case "断开"
ws1.Close
End Select
End SubPrivate Sub Command3_Click()
ws1.SendData Text6.Text ''发送信息
End SubPrivate Sub Form_Load()
Text1.Text = ws1.LocalIP ''在程序运行初期得到本机IP,并在TEXT1内显示
ws1.Protocol = sckTCPProtocol ''设置程序使用协议
End SubPrivate Sub Timer1_Timer()
Select Case ws1.State
Case 0
Label2.Caption = "连接状态为:已关闭"
Command2.Caption = "连接"
Case 1
Label2.Caption = "连接状态为: 打开 "
Case 2
Label2.Caption = "连接状态为:监听"
Case 3
Label2.Caption = "连接状态为:连接挂起"
Case 4
Label2.Caption = "连接状态为:识别主机 "
Case 5
Label2.Caption = "连接状态为:已识别主机"
Case 6
Label2.Caption = "连接状态为:正在连接"
Case 7
Label2.Caption = "连接状态为:已连接"
Command2.Caption = "断开"
Case 8
Label2.Caption = "连接状态为:同级人员正在关闭连接"
Case 9
Label2.Caption = "连接状态为:错误"
End Select
End SubPrivate Sub ws1_ConnectionRequest(ByVal requestID As Long)
Dim bool As Integer
bool = MsgBox("发现连接请求!", vbOKCancel)
If bool = 1 Then
Command2.Caption = "断开"
If ws1.State <> 0 Then
ws1.Close
ws1.Accept requestID
Text2.Text = ws1.LocalPort
Text3.Text = ws1.RemoteHostIP
Text4.Text = ws1.RemotePort
End If
Else
ws1.Close
End If
End SubPrivate Sub ws1_DataArrival(ByVal bytesTotal As Long)
ws1.GetData st
Text5.Text = st
End SubPrivate Sub ws1_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)
MsgBox Number
End Sub
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货