tcpSocket.dataAvailable

I’m trying to accomplish some data processing on the data coming into a tcpSocket. I currently have a thread that monitors a buffer (memoryBlock) and simply have this in the dataAvailable event (handling the processing of the data in the thread itself):

tcpBuffer = tcpBuffer + self.readAll

However, I’m trying to free up the thread approach and am attempting to just handle the data in this event. I have a few questions for those of you who are familiar with handling this class:

  1. If I keep the external buffer approach above as the first line in the dataAvailable event, but process the information further down the dataAvailable event… with something like:
tcpBuffer = right(tcpBuffer, (tcpBuffer.size - packetSize))

Then isn’t there a chance that another dataAvailable event was processed and added data to the ‘tcpBuffer’ before this line is processed, thus causing the tcpBuffer.size to be mismatched with my intentions?

  1. If I just keep another temporary buffer in scope w/ a dim under dataAvailable, and handle my processing that way… only adding to the tcpBuffer afterwards… then isn’t there a chance that the tcpBuffer I have could get out of order if two dataAvailable event hits pretty much back-to-back, and the first event takes a bit longer for me to finish processing before the second one (thus causing the second dataAvailable event writing to the tcpBuffer first)?

This is hurting my head. Hahaha… hope you guys understand the questions! Just trying to play this out in my mind before I go diving into this solution. Thanks!

No. That would be the best way to handle it.

Unless you do something stupid like call DoEvents, the events will not overlap. Another event will not (can not) fire until the current one is finished processing. In fact, if you do too much processing, you will stall your entire app - no events of any kind will be able to fire.

Thanks Tim…