So is this following code, standard?
vb.net Code:
'''********************Class:****************************** Public Class Test Private Sub InitializeHandlers() AddHandler Me.OnConnectionEvent, AddressOf OnConnection 'AddHandler Me.OnAuthentication, AddressOf OnAuthenticated End Sub Public Sub Connect() clientSocket = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp) Dim endpoint As IPEndPoint = New IPEndPoint(Dns.GetHostEntry(_remoteHostIP).AddressList(0), _remotePort) Try clientSocket.Connect(endpoint) If clientSocket.Connected = True Then RaiseEvent OnConnectionEvent(Me, New ConnectionEventArgs(True)) getResponse() End If Catch ex As SocketException RaiseEvent OnConnectionEvent(Me, New ConnectionEventArgs(False, ex.Message)) 'Console.Write(ex.Message) End Try End Sub End Class Public Class ConnectionEventArgs Inherits TcpEventArgs #Region "Decelartions" Private _connected As Boolean Private _data As String #End Region #Region "Constructors" Public Sub New(ByVal connected As Boolean) MyBase.New(-1, "") _connected = connected End Sub Public Sub New(ByVal connected As Boolean, ByVal data As String) MyBase.New(-1, "") _connected = connected _data = data End Sub #End Region #Region "Properties" Public ReadOnly Property Connected() As Boolean Get Return _connected End Get End Property Public ReadOnly Property ConnectionData() As String Get Return _data End Get End Property #End Region End Class '''*************************Program:********************************** Public Sub OnConnection(ByVal sender As Object, ByVal e As ConnectionEventArgs) Console.WriteLine("Connected: " & e.Connected.ToString) End Sub




Reply With Quote