Difference between revisions of "TWSocket.OnDataAvailable"

From Overbyte
Jump to navigation Jump to search
(first entry)
 
Line 20: Line 20:
  
 
== Best practices ==
 
== Best practices ==
* do not call Application.Processmessages or any other form of a message pump (such as TWSocket's message pump or GetMessage) within the event, otherwise you can run into severe reetrancy problems.
+
* do not call Application.Processmessages or any other form of a message pump (such as TWSocket's message pump or GetMessage or any modal form) within the event, otherwise you can run into severe reetrancy problems.
  
 
== How to ==
 
== How to ==

Revision as of 11:31, 13 September 2006

Main page -> ICS component reference -> TWSocket -> OnDataAvailable

Definition

event OnDataAvailable: ? ErrCode:Integer;

Description

OnDataAvailable is rised every time a packet has been received on the interface the corresponding socket is attached (bound) to. In this event you should fetch the received data via Receive, otherwise the event will occur forever. As long as there is still data in the receive buffer of the socket the event will be raised again.

e.g.

  • There were 512 bytes in the buffer
  • you only feteched 256 bytes of them at the first time
  • the OnDataAvailable will occur a second time, since 256 bytes are left
  • if you fetch the other 256 bytes OnDataAvailable stays quiet until the next packet is received

If your program is in the eventhandler now it won't fire again until all the code in the handler has been run, so it may be wise to put long running processing (e.g. database queries) into a worker thread you create in the eventhandler or pass the data to a buffer which is on the other end processed by a thread (so the buffer contents is the thread's workload).

Example

Best practices

  • do not call Application.Processmessages or any other form of a message pump (such as TWSocket's message pump or GetMessage or any modal form) within the event, otherwise you can run into severe reetrancy problems.

How to