P2P的简单示例(VB.net版) 一__教程 |
|
日期:2007-5-20 0:37:34 人气:71 [大 中 小] |
|
|
|
Dim Uname As String = Encoding.Unicode.GetString(data, 4, recvCount - 4)
Dim Uinfobytes() As Byte
Dim i As Integer Dim j As Integer
For i = 1 To userName.Length - 1 If Uname = userName(i) Then Return HVUSER End If Next
For i = 1 To userName.Length - 1 If userName(i) = "" Then userName(i) = Uname userIPEP(i) = userEP userTime(i) = 60 Console.Write(Chr(10) & Chr(13) & "*********************************" & Chr(10) & Chr(13) & Uname.Trim & "上线了." & "用户地址:" & userEP.ToString & Chr(10) & Chr(13) & "*********************************" & Chr(10) & Chr(13)) Console.Write("Server>")
Uinfobytes = Encoding.Unicode.GetBytes(LOGININ & userName(i) & "|" & userIPEP(i).ToString)
For j = 1 To userName.Length - 1 If userName(j) <> "" And userName(j) <> Uname Then ServerSocket.SendTo(Uinfobytes, userIPEP(j)) End If Next Return LOGINOK End If Next
Dim userCount As Integer = userName.Length
ReDim Preserve userName(userCount) ReDim Preserve userIPEP(userCount) ReDim Preserve userTime(userCount)
userName(userName.Length - 1) = Uname userIPEP(userIPEP.Length - 1) = userEP userTime(userTime.Length - 1) = 60
Console.Write(Chr(10) & Chr(13) & "*********************************" & Chr(10) & Chr(13) & Uname.Trim & "上线了." & "用户地址:" & userEP.ToString & Chr(10) & Chr(13) & "*********************************" & Chr(10) & Chr(13)) Console.Write("Server>")
Uinfobytes = Encoding.Unicode.GetBytes(LOGININ & userName(userName.Length - 1) & "|" & userIPEP(userName.Length - 1).ToString)
For j = 1 To userName.Length - 1 If userName(j) <> "" And userName(j) <> Uname Then ServerSocket.SendTo(Uinfobytes, userIPEP(j)) End If Next Return LOGINOK
End Function
'用户登出 Private Sub userloginout(ByVal data As Byte(), ByVal recvCount As Integer)
Dim i As Integer Dim Uname As String = Encoding.Unicode.GetString(data, 4, recvCount - 4)
For i = 1 To userName.Length - 1
If Uname = userName(i) Then
Dim loginOutMsg As String = LOGINOUT & userName(i)
userName(i) = "" userIPEP(i) = Nothing userTime(i) = 0
Dim j As Integer For j = 1 To userName.Length - 1 If userName(j) <> "" Then
sendMsg(loginOutMsg, userIPEP(j))
End If Next
Console.WriteLine(Chr(10) & Chr(13) & "*********************************") Console.WriteLine("用户" & Uname & "下线了.") Console.WriteLine("*********************************") Console.Write("Server>")
Exit For
End If
Next
End Sub
'保持用户在线的过程 Private Sub holdOnLine(ByVal data As Byte(), ByVal recvCount As Integer) |
|
出处:本站原创 作者:佚名 |
|
|