Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ''' <summary>
- ''' Logging Level enums
- ''' </summary>
- ''' <remarks></remarks>
- Public Enum Logging_Level
- None = 0
- Normal = 1
- IncludeDebug = 2
- SystemWarnings = 3
- Exceptions = 4
- End Enum
- '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
- ''''' ArkMessenger TCPV3.vb
- ''''' Version 3.0
- ''''' Developer: Adam Sears
- ''''' Rewrite: #3
- ''''' Changelog:
- '''''
- ''''' 11/08/10
- ''''' Expanded the powers of the CManager Class to handle most Client interactions
- ''''' Integrated the handlers of various structures that the system will use.
- '''''
- ''''' 11/07/10
- ''''' First successful test of the code. Added in Chatroom Manager (CRManager)
- '''''
- ''''' 11/02/10
- ''''' Cleaned up the [Client] Class code.
- ''''' Finalized some Server routines
- '''''
- ''''' 10/25/10
- ''''' Implemented the Client Manager (CManager)
- ''''' Implemented the Client Saver (C_SaveLoad)
- ''''' Cleaned up TCPV3 base class.
- ''''' Cleaned up Server base class.
- '''''
- ''''' 10/20/10
- ''''' Started and finished TCPV3 base class.
- ''''' Started and finished Server base class.
- '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
- ''' <summary>
- ''' Handles all low level server side incoming messages.
- ''' </summary>
- ''' <remarks></remarks>
- Public Class TCPV3
- ''' <summary>
- ''' Returns the port the TCPV3 Class is listening on.
- ''' </summary>
- ''' <value></value>
- ''' <returns></returns>
- ''' <remarks></remarks>
- Public ReadOnly Property Port As Integer
- Get
- Return _port
- End Get
- End Property
- ''' <summary>
- ''' This sub is called whenever an Incoming Connection is established.
- ''' </summary>
- ''' <param name="ir">The IAsyncResult Data.</param>
- ''' <remarks></remarks>
- Public Overridable Sub OnIncomingConnection(ByVal ir As IAsyncResult)
- Me.Logging("SYSTEM: Connection established, passing TcpClient on.", Logging_Level.SystemWarnings)
- 'Grab the new client.
- Dim client As TcpClient = _listener.EndAcceptTcpClient(ir)
- 'Client grabbed, raise event passing it back up.
- RaiseEvent IncomingConnection(client)
- Me.Logging("SYSTEM: Passed on, ready for another connection.", Logging_Level.SystemWarnings)
- 'Setup for the next connection.
- _listener.BeginAcceptTcpClient(New AsyncCallback(AddressOf Me.OnIncomingConnection), _listener)
- End Sub
- 'Events
- Public Event IncomingConnection(ByRef client As TcpClient)
- Public Event Log(ByVal text As String)
- 'Variable List
- Private _listener As TcpListener
- Private _port As Integer = 6110I
- Private _listening As Boolean = False
- Public _logging As Logging_Level = Logging_Level.Normal
- ''' <summary>
- ''' Creates a new TCPV3 Class with the default listener port.
- ''' </summary>
- ''' <remarks></remarks>
- Public Sub New()
- 'If not listening, create a new listener.
- 'If Not _listening Then _listener = New TcpListener(IPAddress.Any, _port)
- End Sub
- ''' <summary>
- ''' Creates a new TCPV3 Class with the specified port.
- ''' </summary>
- ''' <param name="Port">The port to listen on.</param>
- ''' <remarks></remarks>
- Public Sub New(ByVal Port As Integer)
- 'If not listening, set the ports up and create the listener.
- If Not _listening Then
- _port = Port
- '_listener = New TcpListener(IPAddress.Any, _port)
- End If
- End Sub
- ''' <summary>
- ''' Starts the TCPV3 listener.
- ''' </summary>
- ''' <remarks></remarks>
- Public Sub Start()
- 'If we're not listening, we are allowed to start.
- If Not _listening Then
- 'Say that we ARE listening.
- _listening = True
- 'Create the listener
- _listener = New TcpListener(IPAddress.Any, Port)
- Me.Logging("SYSTEM: Listener created, activating...", Logging_Level.SystemWarnings)
- 'Start the actual listener.
- _listener.Start()
- 'Get ready for the new Clients.
- _listener.BeginAcceptTcpClient(New AsyncCallback(AddressOf Me.OnIncomingConnection), _listener)
- Me.Logging("SYSTEM: Waiting for incoming connections...", Logging_Level.SystemWarnings)
- End If
- End Sub
- ''' <summary>
- ''' Stops the TCPV3 listener.
- ''' </summary>
- ''' <remarks></remarks>
- Public Sub [Stop]()
- 'If we are in fact listening then go ahead and disable all the listening.
- If _listening Then
- Me.Logging("SYSTEM: Listener stopped.", Logging_Level.SystemWarnings)
- _listening = False
- _listener.Stop()
- End If
- End Sub
- ''' <summary>
- ''' Raises events to logs.
- ''' </summary>
- ''' <param name="text">The text to log.</param>
- ''' <param name="level">The level of the log.</param>
- ''' <remarks></remarks>
- Private Sub Logging(ByVal text As String, ByVal level As Logging_Level)
- If level <= _logging Then RaiseEvent Log(String.Format("TCPV3 Log: {0}", text))
- End Sub
- End Class
- 'End of File
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement