Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.Threading
- Imports System.Net
- Imports System.Net.Sockets
- Imports System.IO
- Public Class Client
- Private client As TcpClient
- Private netStream As NetworkStream
- Public Shared Property incommingBytes As Long = 0
- Public Shared Property outcommingBytes As Long = 0
- Private Shared incommingBytesLock As New Object
- Private Shared outcommingBytesLock As New Object
- Public ReadOnly Property remoteIp As String = String.Empty
- Public Event IncommingData(ByRef c As Client, ByVal header As Byte, ByVal buffer() As Byte)
- Public Event Disconnected(ByRef c As Client)
- Sub New(ByRef c As TcpClient)
- client = c
- Try
- remoteIp = c.Client.RemoteEndPoint.ToString
- netStream = client.GetStream()
- netStream.BeginRead(New Byte() {0}, 0, 0, AddressOf ReadAsync, Nothing)
- Catch ex As Exception
- RaiseEvent Disconnected(Me)
- End Try
- End Sub
- Private Sub ReadAsync(ByVal iAR As IAsyncResult)
- Try
- 'You read here
- RaiseEvent IncommingData(Me, header, buffer)
- netStream.BeginRead(New Byte() {0}, 0, 0, AddressOf ReadAsync, Nothing)
- Catch ex As Exception
- RaiseEvent Disconnected(Me)
- End Try
- End Sub
- Public Sub SendAsync(ByVal header As Byte)
- Try
- 'You write here
- Catch ex As Exception
- RaiseEvent Disconnected(Me)
- End Try
- End Sub
- Public Sub SendAsync(ByVal header As Byte, ByVal buffer() As Byte)
- Try
- 'You write here
- Catch ex As Exception
- RaiseEvent Disconnected(Me)
- End Try
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement