Asynchronous Communication library casyncsocketex on Windows

Source: Internet
Author: User

Asynchronous Communication library casyncsocketex on Windows

 

 

 

Casyncsocketex is a small library (http://www.codeproject.com/KB/IP/casyncsocketex.aspx) released to codeproject.com in 2003 by Tim kosse, which is a substitute and improved product for casyncsocket of MFC.

 

As asynchronous communication, the casyncsocketex model, or execution mode, is similar to the casyncsocket of the original MFC. Their Asynchronization is not implemented by themselves, the core is to call the wsaasyncselect () interface provided by windows ().

 

Wsaasyncselect (m_socketdata.hsocket, gethelperwindowhandle (), m_socketdata.nsocketindex + wm_socketex_notify,
Levent)

 

Wsaasyncselect () is used for each socket, and the next network event with these sockets (for example, the network data is received or the connection is established successfully ), windows will ship all Socket network events to the thread message queue for asynchronous processing of network Io.

 

Shows its general architecture.

 

 

 

 

 

 

When the thread creates the first casyncsocketex, A casyncsocketexhelperwindow is instantiated. Each thread has only one casyncsocketexhelperwindow.

 

List m_spasyncsocketexthreaddatalist is a static variable that records the ID of all the threads that created casyncsocketex, and the number of helperwindow and casyncsocketex.

 

Because it is asynchronous, it is also suitable for single-threaded programs. You can process everything in one thread without having to create an independent thread for network I/O. Of course, a thread takes care of all things and has its inherent shortcomings in some cases. This is not detailed here.

 

One difference between casyncsocketex and MFC's casyncsocket is that it has improved the delivery of network affairs. In a casyncsocketexhelperwindow
In (associated with a thread), each socket (casyncsocketex) maps different message IDs, so that when a message arrives at the window casyncsocketexhelperwindow, the array is directly accessed using the Message ID as the index, directly obtain the corresponding socket (casyncsocketex), instead of looking for it like the casyncsocket of MFC.

 

 

Casyncsocketex also introduces the layer concept. you can insert several layers (casyncsocketexlayer) in casyncsocketex without changing the external programming interface of casyncsocketex. When sending data, the data passes through the last layer from the first layer of casyncsocketexlayer, and then to the socket interface of Windows. The path for receiving data is reversed, as shown in.

 

 

 

 

 

With this flexible layer design, the casyncsocketex Library also implements the proxy layer. You only need to instantiate a casyncproxysocketlayer in the program and add it to casyncsocketex to support proxy server connection. Socks proxy and HTTP Proxy are supported.

 

Casyncsocketex is used. For more information about its practical application, see the code of the plug-in.



Bytes -------------------------------------------------------------------------------------------------

For more blog posts, please subscribe to RSS. For more Weibo posts, please follow @ Qianli lone row nerd

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.