下面是引用三仙于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)
红色字那他说地址已用过我该怎么处理@@?