In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you how to achieve the VB.NET server, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
This is a simple P 2 P example implemented with VB.NET, using UDP hole drilling technology. The server side and the client side are responsible for logging in, recording the user's IP and port, and forwarding hole messages (there are many related technologies in CSDN). The principles are everywhere. The VB.NET code is posted here for beginners to communicate. Experts are also welcome to comment.
After the VB.NET server is started successfully, enter help to view the server-related commands. After the client has successfully logged in, enter help to view the relevant commands on the client. (the user name is casual when logging in)
The following is the VB.NET server side:
Imports System.Net
Imports System.Net.Sockets
Imports System.Text
Imports System.Threading
Imports System.Collections
Module myUDPServer
# Region "Global variable"
Dim ServerSocket As New Socket (AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp)
Dim ipep As IPEndPoint = New IPEndPoint (IPAddress.Any, 11000)
Dim htUserList As New Hashtable'is used to save "IP and ports" for online users and users
Dim userName (0) As String
Dim userIPEP (0) As IPEndPoint
Dim userTime (0) As Integer
Dim timerDelegate As New TimerCallback (AddressOf onLineTimeOut)
# End Region
# Region "parameters"
'The following is the beginning of the client-to-server message
Const LOGININ As String = "10" 'message requesting login | message form: 10 + your user name
Const LOGINOUT As String = "11" 'request logout message | message form: 11 + your own user name
Const GETULIST As String = "12" 'request for online user list | message format: 12
Const P2PCONN As String = "13" 'message requesting P2P connection | message form: 13 + your own user name + | + other party's user name
Const HOLDLINE As String = "14" 'keep connected. | message open mode: 14 + your own user name
'The following is the beginning of the server-to-client message
Const HVUSER As String = "20" 'username already exists
Const GETUSER As String = "21" 'online user list | message format: 21 + user name + EP
Const MAKHOLD As String = "22" 'punch command | message format: 22+IP
Const LOGINOK As String = "23" 'logged in successfully
Const SERVCLS As String = "24" 'Server shuts down
Const MSGEND As String = "25" 'message ends
'The following are the server-side names
Const EXITPRO As String = "EXIT" 'exit command
Const SHOWULIST As String = "SHOWUSER" 'shows online users
Const HELP As String = "HELP" 'display help
# End Region
# Region "method"
'main function, program entry
Sub Main ()
'get the IP address of the server
Dim addressList As System.Net.IPAddress () = Dns.GetHostByName (Dns.GetHostName ()) .AddressList
Dim ServerIP As IPAddress = addressList (0)
ServerSocket.Bind (ipep)
Console.WriteLine ("the server is starting.")
Console.WriteLine ("Server IP:" & ServerIP.ToString & "listening" & ipep.Port.ToString & "Port")
Dim listenTH As New Thread (AddressOf listen)
ListenTH.Start () 'enable listening thread
Console.WriteLine ("Server started successfully.")
Dim timer As New Timer (timerDelegate, Nothing, 0, 5000)
Dim SVInput As String
While True
Console.Write ("Server >")
SVInput = Console.ReadLine () .ToUpper
Select Case SVInput
Case EXITPRO
ListenTH.Abort ()
ServerSocket.Close ()
Exit Sub
Case SHOWULIST
ShowUser ()
Case HELP
Console.Write ("*" & Chr (10) & Chr (13) & "exit: output the current Program" & Chr (10) & Chr (13) &
"showuser: show the current online user case table" & Chr (10) & Chr (13) &
Help: show help & Chr (10) & Chr (13) & "*" & Chr (10) & Chr (13)
Case Else
Console.WriteLine ("*" & Chr (10) & Chr (13)
& "stupid, you are not entering a valid command." & Chr (10) & Chr (13) & "*")
End Select
End While
End Sub
The above is all the contents of the article "how to implement the VB.NET server side". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.