-
Notifications
You must be signed in to change notification settings - Fork 64
/
Connection.vb
46 lines (46 loc) · 1.57 KB
/
Connection.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
Imports System.Net
Imports System.Net.Sockets
Imports System.IO
Public Class Connection
Private client As TcpClient
Private IP As String
Private _Socket As String
Public Event GotInfo(ByVal client As Connection, ByVal Message As String)
Public Event Disconnected(ByVal client As Connection)
Sub New(ByVal client As TcpClient)
Me.client = client
client.GetStream().BeginRead(New Byte() {0}, 0, 0, AddressOf Read, Nothing)
IP = client.Client.RemoteEndPoint.ToString().Remove(client.Client.RemoteEndPoint.ToString().LastIndexOf(":"))
_Socket = client.Client.RemoteEndPoint.ToString().Split(":")(1)
End Sub
Sub Read(ByVal ar As IAsyncResult)
Dim Message As String
Try
Dim reader As New StreamReader(client.GetStream())
Message = reader.ReadLine()
RaiseEvent GotInfo(Me, Message) 'RemoteDesktop
client.GetStream().BeginRead(New Byte() {0}, 0, 0, AddressOf Read, Nothing)
Catch ex As Exception
RaiseEvent Disconnected(Me)
End Try
End Sub
Public Sub Send(ByVal Message As String)
Try
Dim writer As New StreamWriter(client.GetStream())
writer.WriteLine(Message)
writer.Flush()
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
End Sub
Public ReadOnly Property IPAddress
Get
Return IP
End Get
End Property
Public ReadOnly Property RemoteSocket
Get
Return _Socket
End Get
End Property
End Class