下面是引用三仙於2008-09-19 21:13發表的 :
做法都是一樣的
如果要寫像msn那種ap
建議寫一個server端(db型態)
這樣也可以防止nat的問題
我是了過後...有一些些小問題...
server端
'---------------------------------------------------------------------------------------------------------
Dim wk(1000) As Integer
Dim win As Integer
Private Sub Form_Load()
win = 0
Winsock1(win).LocalPort = 1001
Label1.Caption = "已斷開連線!"
Winsock1(win).Listen
End Sub
Private Sub Winsock1_Close(Index As Integer)
Winsock1(Index).Close
Label1.Caption = "已經連線 !"
wk(Index) = 0
Print Index; " 以斷線"
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.Caption = "已經連線 !"
wk(i) = 1
Print i; " 以連線"
Winsock1(i).Accept requestID
win = win + 1
Load Winsock1(win)
Winsock1(win).LocalPort = 1001
Winsock1(win).ListenEnd If
Next i
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.Caption = "已經連線 !"
wk(Index) = 0
Print Index; " 以斷線"
End Sub
'---------------------------------------------------------------------------------------------------------
連結端
'---------------------------------------------------------------------------------------------------------
Private Sub Command1_Click() '連線
Winsock1.Close
Winsock1.RemoteHost = Text1.Text
Winsock1.RemotePort = 1001
Label1.Caption = "連線中 ..."
Winsock1.Connect
End Sub
Private Sub Command2_Click() '斷開
Winsock1.Close
Label1.Caption = "已斷開連線!"
End Sub
Private Sub Form_Load()
Winsock1.Close
Winsock1.RemotePort = 1001
Label1.Caption = "斷開 ..."
Winsock1.Listen
End Sub
Private Sub Winsock1_Close()
Winsock1.Close
Label1.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)
Winsock1.Close
Label1.Caption = "已斷開連線!"
End Sub
'---------------------------------------------------------------------------------------------------------
我先按連線(Command1),後按斷開(Command2),在按連線(Command1)
紅色字那他說地址已用過我該怎麼處理@@?