P2P的简单示例(VB.net版) 一__教程 |
|
日期:2007-5-20 0:37:34 人气:71 [大 中 小] |
|
|
|
Dim Uname As String = Encoding.Unicode.GetString(data, 4, recvCount - 4)
Dim i As Integer
For i = 1 To userName.Length - 1
If Uname = userName(i) Then
userTime(i) = 60 Exit For
End If
Next
End Sub
'用户超时退出 Private Sub onLineTimeOut(ByVal state As [Object])
Dim i As Integer
For i = 1 To userName.Length - 1
If userTime(i) > 0 Then
userTime(i) -= 5
If userTime(i) <= 0 Then
Dim loginoutmsg As String = LOGINOUT & userName(i)
Console.WriteLine(Chr(10) & Chr(13) & "*********************************") Console.WriteLine("用户" & userName(i) & "下线了.") Console.WriteLine("*********************************") Console.Write("Server>")
userName(i) = "" userIPEP(i) = Nothing
Dim ULoginOutbytes() As Byte = Encoding.Unicode.GetBytes(loginoutmsg)
Dim j As Integer For j = 1 To userName.Length - 1
If userName(j) <> "" Then If userIPEP(j) Is Nothing Then Else ServerSocket.SendTo(ULoginOutbytes, userIPEP(j)) End If End If
Next
End If
End If
Next
End Sub
'发送消息的函数 Sub sendMsg(ByVal msg As String, ByVal remoteEP As IPEndPoint) Dim sendBytes As [Byte]() = Encoding.Unicode.GetBytes(msg) Try
ServerSocket.SendTo(sendBytes, remoteEP)
Catch e As Exception Console.WriteLine(e.ToString()) End Try End Sub
#End Region
End Module |
|
出处:本站原创 作者:佚名 |
|
|