回复 6楼 事业男儿
那就试试这个
程序代码:
Option Explicit
Dim ifConnect As Boolean
Dim refuse As Boolean
Private Sub Form_Load()
Form1.Show
Winsock2.LocalPort = 5000
Winsock2.Listen
Winsock1.Protocol = sckTCPProtocol
Winsock1.LocalPort = 5001
Winsock1.Connect "127.0.0.1", 5000
Do
DoEvents
Loop Until refuse Or ifConnect
If refuse Then
Form1.Caption = "强行拒绝"
Winsock1.Close
Winsock2.Close
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
Winsock1.Close
Winsock2.Close
End Sub
Private Sub Winsock1_Connect()
ifConnect = True
Form1.Caption = "已连接"
End Sub
Private Sub Winsock1_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)
If Number = 10061 Then refuse = True
End Sub