Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27333

VS 2010 Speed up received message converted to string

$
0
0
Hi all.

I have my Async sockets working perfectly thanks to some help from some kind people here however I have now discovered that it misses some communications if they are quick. This is connecting to a chat server I have no control over the speed of sent messages but upon testing I can get it to miss a substantial amount of incoming messages and it all seems to be linked to the conversion of the message from a byte array to a string.

Here is the onreceive routine:

VB.Net Code:
  1. Private Sub OnReceive(ByVal ar As IAsyncResult)
  2.  
  3.             _Client.EndReceive(ar)
  4.  
  5.             Dim msg As String = System.Text.ASCIIEncoding.ASCII.GetString(_Bytes)
  6.             Array.Clear(_Bytes, 0, _Bytes.Length)
  7.  
  8.             _Client.BeginReceive(_Bytes, 0, _Bytes.Length, SocketFlags.None, New AsyncCallback(AddressOf OnReceive), _Client)
  9.  
  10.             RaiseEvent ReceiveMessage(msg)
  11.  
  12.         End Sub

If another message is sent to the bot between the start of this rountine and the 4th line it misses it. On hammering the chat 20 lines the bot only sees 13. Is there anyway I can speed up the above code or do it a different way to get it ready to receive the next message quicker?

Thanks,
Max

Viewing all articles
Browse latest Browse all 27333

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>