圖 1.
我給了對方"MSWINSCK.OCX"
但是卻出現下面著個問題
執行階段錯誤'400060'
對所要求的交易或要求而言,通訊協定(procol)不適合或連線狀態有誤
請問我程式碼哪裡出錯了??
sever
--------------------------------------------------------------------------------
Dim wk(1000) As Integer
Dim win As Integer
Dim tempne As Integer
Dim tempstr As String
Dim account, account_sever As String
Dim password, password_sever As String
Private Sub Form_Load()
win = 0
Winsock1(win).LocalPort = 1024
Label1(win).Caption = "已斷開連線!"
Winsock1(win).Listen
End Sub
Private Sub Winsock1_Close(Index As Integer)
Winsock1(Index).Close
Label1(Index).Caption = "已斷開連線!"
wk(Index) = 0
End Sub
Private Sub Winsock1_ConnectionRequest(Index As Integer, ByVal requestID As Long)
For i = 0 To win
If wk(i) = 0 Then
Winsock1(i).Close
Label1(i).Caption = "已經連線 !"
wk(i) = 1
Winsock1(i).Accept requestID
wink = 0
For k = 0 To 1000
If wk(k) = 1 Then wink = wink + 1
Next k
If wink = win + 1 Then
win = win + 1
Load Winsock1(win)
Load Label1(win)
Load Label2(win)
Label1(win).Visible = True
Label2(win).Visible = True
Label1(win).Caption = ""
Label2(win).Caption = ""
Label1(win).Left = Label1(win - 1).Left
Label1(win).Top = Label1(win - 1).Top + 240
Label2(win).Left = Label2(win - 1).Left
Label2(win).Top = Label2(win - 1).Top + 240
Winsock1(win).LocalPort = 1024
Winsock1(win).Listen
End If
Exit For
End If
Next i
End Sub
Private Sub Winsock1_DataArrival(Index As Integer, ByVal bytesTotal As Long)
Winsock1(Index).GetData tempstr
Label2(Index).Caption = tempstr
tempne = Index
find = Mid(tempstr, 1, 2)
If find = "ap" Then Call test_ap
End Sub
Private Sub Winsock1_Error(Index As Integer, 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)
Winsock1(Index).Close
Label1(Index).Caption = "已斷開連線!"
wk(Index) = 0
End Sub
Sub test_ap()
Dim result_end As String
find_a = InStr(tempstr, "a=")
find_p = InStr(tempstr, "p=")
account = Mid(tempstr, find_a + 2, Len(tempstr) - find_p - 1)
password = Mid(tempstr, find_p + 2, Len(tempstr))
Print account
Print password
Open "at&pd\player.ap" For Input As #1
Do While Not EOF(1)
Input #1, account_sever
Input #1, password_sever
If account_sever = account Then
If password_sever = password Then
result_end = "test_ap_OK"
Exit Do
End If
End If
result_end = "test_ap_NO"
Loop
Winsock1(tempne).SendData result_end
Close #1
End Sub
用戶端
------------------------------------------------------------------------------------------------
Private Sub Command1_Click()
ww = "ap" & "a=" & Text1.Text & "p=" & Text2.Text
Winsock1.SendData ww
End Sub
Private Sub Form_Load()
Winsock1.Close
Label3.Caption = "已斷開連線!"
If Text3.Text = "" Then
Label3.Caption = "請輸入主機名稱!"
Exit Sub
End If
Winsock1.RemoteHost = Text3.Text
Winsock1.RemotePort = 1024
Winsock1.Connect
End Sub
Private Sub Timer1_Timer()
Winsock1.Close
Label3.Caption = "已斷開連線!"
If Text3.Text = "" Then
Label3.Caption = "請輸入主機名稱!"
Exit Sub
End If
Winsock1.RemoteHost = Text3.Text
Winsock1.RemotePort = 1024
Winsock1.Connect
End Sub
Private Sub Winsock1_Close()
Winsock1.Close
Timer1.Enabled = True
Label3.Caption = "已斷開連線!"
End Sub
Private Sub Winsock1_Connect()
Label3.Caption = "連線中 ..."
Timer1.Enabled = False
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim strData As String
Winsock1.GetData strData
If strData = "test_ap_OK" Then Label3.Caption = "登入成功!"
If strData = "test_ap_NO" Then Label3.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)
Label3.Caption = "已斷開連線!"
Label3.Caption = Description
Winsock1.Close
End Sub