Jul 2, 2019 08:13 PM
(This post was last modified: Jul 2, 2019 08:17 PM by MalwareMop.)
I'm trying to send data to the server consistently without pause in a loop, however, when I do so the buffer seems to become offset, and doesn't contain the "expected" packet header and thus fails to read the bytes. I'm fairly stumped on how to fix this issue. If anyone knows what I'm doing wrong please let me know, and any examples would be great. I've not been able to find an answer yet.
The exact error is when the StreamWindow routine begins, shortly after, the stream of data in the receive buffer will contain half of the old sent packet and half of a new packet again as explained above making it so I'm unable to read the "header" bytes of the packet to determine what to do.
Hope someone can help.
SocketObject
The RecieveCallback
Send Loop
The exact error is when the StreamWindow routine begins, shortly after, the stream of data in the receive buffer will contain half of the old sent packet and half of a new packet again as explained above making it so I'm unable to read the "header" bytes of the packet to determine what to do.
Hope someone can help.
SocketObject
Code
Public Class SocketObject
Public Socket As Socket
Public Buffer As Byte()
Public Sub New(ByVal Sckt As Socket, ByVal Bffer As Byte())
Me.Socket = Sckt
Me.Buffer = Bffer
End Sub
End ClassThe RecieveCallback
Code
Public Sub ReceivedCallback(ByVal Result As IAsyncResult)
Dim SocketObject As SocketObject = CType(Result.AsyncState, SocketObject)
Dim SocketError As SocketError
Dim BufferSize As Integer = SocketObject.Socket.EndReceive(Result, SocketError)
If SocketError.Equals(SocketError.Success) Then
Dim Packet(BufferSize) As Byte
Buffer.BlockCopy(SocketObject.Buffer, 0, Packet, 0, BufferSize)
HandlePacket(Packet)
If SocketObject.Socket.Connected Then
ReDim SocketObject.Buffer(ServerBufferSize)
SocketObject.Socket.BeginReceive(SocketObject.Buffer, 0, SocketObject.Buffer.Length, SocketFlags.None, New AsyncCallback(AddressOf ReceivedCallback), SocketObject)
Else
SocketObject.Socket.Close()
End If
ElseIf SocketError.Equals(SocketError.ConnectionRefused) Then
'User Disconnected
ElseIf SocketError.Equals(SocketError.ConnectionAborted) Then
'User Disconnected
ElseIf SocketError.Equals(SocketError.ConnectionReset) Then
'User Disconnected
End If
End SubSend Loop
Code
Public Sub StreamLoop(ByVal ChunkDelay As Integer)
While Streaming AndAlso ClientSocket.Connected
Dim Image As Image = TakeWindowScreenshot(GetCaption)
Dim ImageBytes As Byte() = ConvertImageToBytes(Image)
Dim CompressedBytes As Byte() = Compress(ImageBytes)
SendChunkedPacket(ClientSocket, 200, CompressedBytes)
SetLabelText(LblSentLength, String.Format("Length: {0}", ImageBytes.Length.ToString("N0")))
System.Threading.Thread.Sleep(ChunkDelay)
End While
End Sub


