下载首页 | 资讯中心 | 下载分类 | 最近更新 | 排 行 榜 | 国产软件 | 国外软件 | 汉化补丁 |
文章搜索: 分类 关键字 收藏本站设为首页
您的位置:首页网页设计ASP程序 → P2P的简单示例(VB.net版) 一__教程
P2P的简单示例(VB.net版) 一__教程
日期:2007-5-20 0:37:34 人气:71     [ ]
上一页 [1] [2] [3] [4] 下一页


End Sub

'打印在线用户
Sub showUser()
Dim hava As Boolean = False
If userName.Length <> 0 Then
Dim i As Integer
For i = 1 To userName.Length - 1
If userName(i) <> "" Then
hava = True
Exit For
End If
Next
If hava = False Then
Console.WriteLine("*********************************" & Chr(10) & Chr(13) & "当前没有用户在线" & Chr(10) & Chr(13) & "*********************************")
Exit Sub
End If
Console.WriteLine("*********************************")
For i = 1 To userName.Length - 1
If userName(i) <> "" Then
Console.WriteLine("用户名:" & userName(i) & " 地址:" & userIPEP(i).ToString)
End If
Next
Console.WriteLine("*********************************")
Else
Console.WriteLine("*********************************" & Chr(10) & Chr(13) & "当前没有用户在线" & Chr(10) & Chr(13) & "*********************************")
End If
End Sub

'服务器监听函数
Sub listen()

While True

Try
Dim recv As Integer = 0
Dim data As [Byte]() = New Byte(1024) {}
Dim sender As New IPEndPoint(IPAddress.Any, 0)
Dim tempRemoteEP As EndPoint = CType(sender, EndPoint)
recv = ServerSocket.ReceiveFrom(data, tempRemoteEP)

'Console.WriteLine(Encoding.Unicode.GetString(data))

Dim msgHead As String = Encoding.Unicode.GetString(data, 0, 4)
Select Case msgHead
Case LOGININ
Dim LoginThing As String = userLogin(data, tempRemoteEP, recv)
If LoginThing = HVUSER Then
sendMsg(HVUSER, tempRemoteEP)
ElseIf LoginThing = LOGINOK Then
sendMsg(LOGINOK, tempRemoteEP)

End If

Case LOGINOUT
userloginout(data, recv)

Case GETULIST
Dim userinfo As String = getUserList()
sendMsg(userinfo, tempRemoteEP)

Case P2PCONN
questP2PConn(data, recv)

Case HOLDLINE
holdOnLine(data, recv)
End Select

Catch e As Exception
'Console.WriteLine(e.ToString)
End Try
End While

End Sub

'转发P2P连接请求
Private Sub questP2PConn(ByVal data() As Byte, ByVal recv As Integer)

Dim recvStr As String = Encoding.Unicode.GetString(data, 4, recv - 4)
Dim split() As String = recvStr.Split("|")

Dim fromEP As IPEndPoint
Dim toEP As IPEndPoint
Dim i As Integer
For i = 1 To userName.Length - 1
If userName(i) = split(0) Then
fromEP = userIPEP(i)
End If
If userName(i) = split(1) Then
toEP = userIPEP(i)
End If
Next
Dim holdbytes() As Byte = Encoding.Unicode.GetBytes(MAKHOLD & fromEP.ToString)
ServerSocket.SendTo(holdbytes, toEP)
End Sub

'函数.返回所有在线用户.其格式:用户名+|+用户IPEP+|
Private Function getUserList() As String
Dim userInfo As String = GETUSER
Dim i As Integer
For i = 1 To userName.Length - 1
If userName(i) <> "" Then
userInfo += userName(i) & "|" & userIPEP(i).ToString & "|"
End If
Next
Return userInfo
End Function

'用户登陆,直接返回登陆是否成功的值
Private Function userLogin(ByVal data As Byte(), ByVal userEP As IPEndPoint, ByVal recvCount As Integer) As String
出处:本站原创 作者:佚名
 阅读排行
01.精美qq空间横幅代码
02.最酷qq个性女生网名
03.最新又有免费QQ秀啦《..
04.巧用透明FlaSh扮靓你的..
05.花之神匠代码(最新代码..
06.最新QQ空间免费导航
07.最新免费个人形象设置..
08.最新qq空间flash代码m..
09.CSS技术结合图像实现动..
10.Photoshop光影魔术师:..
11.QQ音速种子狂刷
12.最新QQ空间透明代码
13.PS实例教程:教你制作结..
14.Photoshop光影魔术师:..
15.制作背景图__教程
16.用Photoshop制作漂亮的..
17.如何获得QQ音速种子
18.≤QQ空间代码≥在日志..
19.网页浮动广告的制作代..
20.用Photoshop制作大红灯..
21.常用CSS
22.Photoshop给靓丽美女打..
 推荐文章
·Photoshop 表现技法之..
·快速将你的相片矢量化..
·PHOTOSHOP制作炽热的太..
·用Photoshop制作美丽的..
·流行杀手的娃娃工厂__..
·打造8号台球__教程
·PHOTOSHOP制作待机MM图..
·用Photoshop帮MM做纹身..
·PHOTOSHOP美眉着色绝招..
·PHOTOSHOP花露的制作_..
·PHOTOSHOP渐变工具的巧..
·PHOTOSHOP手绘奥兰多-..
·高难度抠图两种方法__..
·Photoshop高尔夫球的制..
·Photoshop打造精美玉佩..
Eqxia_COM下载站 版权所有 Copyright© 2001-2005 Www.eqxia.COM, All Rights Reserved.