Limitations

The Winsock control is clearly useful and easy to use; unfortunately, a few bugs make the control unusable for mission-critical applications. The bugs discussed in this section apply to the latest version of the control for Visual Basic 5.0, which is the updated control from Service Pack 2.

The first bug is relatively minor and deals with dynamically loading and unloading the control. A memory leak is incurred when unloading a previously loaded control. This is why we don't load and unload the controls as clients connect and disconnect in our server example. Once the control is loaded in memory, we leave it for possible use by other clients.

The second bug involves closing a socket connection before all data queued is sent on the wire. In some cases, calling the Close method after the SendData event (when Close is processed before SendData) causes data to be lost, at least from the receiver's point of view. You can get around this problem by catching the SendComplete event (which is triggered when SendData has finished putting the data on the wire). Alternatively, you could arrange the send/receive transactions so that the receiver issues the Close command first, when it has received all the data expected. This would then trigger the Close event on the sender, which would then signal that all the data sent has been received, and that it's now OK to shut down the connection completely.

The last and most severe bug is the dropping of data when a large buffer is submitted for transfer. If a large enough block of data is queued up for network transmission, the control's internal buffers get messed up and some data is dropped. Unfortunately, there is no completely perfect workaround for this problem. The best method is to submit data in chunks less than 1000 bytes. Once a buffer is submitted, wait for the SendComplete event to fire before submitting the next buffer. This is a pain, but it's still the best way to make the control as reliable as possible.

The latest Winsock control shipping in Visual Basic 6.0 has fixed the bugs above except for the second one. If you issue a Close command after calling SendData, the socket closes immediately without sending all the data. While it would have been wonderful to have all the bugs fixed, the remaining problem is perhaps the least severe of the three and the easiest to work around.



Network Programming for Microsoft Windows
Linux Server Hacks, Volume Two: Tips & Tools for Connecting, Monitoring, and Troubleshooting
ISBN: 735615799
EAN: 2147483647
Year: 1998
Pages: 159

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net