use more inherit features

This commit is contained in:
schedpas
2020-06-09 07:49:31 +02:00
parent 49e45e50cd
commit 6e33874df6
4 changed files with 33 additions and 32 deletions

View File

@@ -12,6 +12,7 @@ Public Class UDPManager
Private listenTask As Task = Nothing
Private ReadOnly cancelTokenSource As New CancellationTokenSource
Private ReadOnly cancelToken As CancellationToken = cancelTokenSource.Token
Public ReadOnly Property MaxBufferSize As Integer = &H10000
Public Sub New(port As Integer)
MyBase.New(port)
@@ -62,29 +63,18 @@ Public Class UDPManager
Dim buf As Byte() = receiveTask.Result.Buffer
Dim ip As String = receiveTask.Result.RemoteEndPoint.Address.ToString
Dim cmd As String = String.Empty
Dim content As Object = Nothing
doExit()
Try
Dim res = DecodeFromBytes(buf)
cmd = res.cmd
content = res.content
Catch ex As Exception
End Try
RaiseRetriveData(ip, cmd, content)
ProcessRetrivedData(ip, buf)
doExit()
StartInternal()
End Sub
Public Overrides Sub Send(empfängerIP As String, cmd As String, content As Object)
Dim ep As New IPEndPoint(GetIPFromHost(empfängerIP).MapToIPv4, Port)
Protected Overrides Sub SendData(ep As IPEndPoint, buf As Byte())
Dim udp As New UdpClient
Dim buf As Byte() = EncodeToBytes(cmd, content, UseAssemblyQualifiedName)
udp.Connect(ep)
udp.Send(buf, buf.Length)
udp.Client.Shutdown(SocketShutdown.Both)