"You are now using this SocketAsyncEventArgs instance for asynchronous socket operations" processing

Source: Internet
Author: User

"An asynchronous socket operation is now being used with this SocketAsyncEventArgs instance"

Found that a lot of people in the use of SocketAsyncEventArgs for high-performance communication development encountered this problem, but there is no specific solution on the network, so record sharing under my processing method

First, this problem typically occurs when an access connection, and data is sent, received

1. This exception is thrown when the connection is received, it is necessary to synchronize the receive connection, wait with Semaphor

2. The core of using SocketAsyncEventArgs is to implement object reuse, reduce the allocation and recycling of objects to improve program performance. Usually using a stack or queue to manage asynchronous objects, I'm using a stack

Stack pools are LIFO, the reception of multithreaded data, the sending and the pop of objects, the push is confusing (so it should be better to use a queue), so you need to implement synchronization between them

The synchronous implementation is done by using lock when a connection is broken to ensure that the operation of the asynchronous object is synchronized, because only the pop and push of the asynchronous object are available when the connection is broken.


The above is only my personal solution to this problem of thinking and methods, specific analysis, hope can help you

This article is from the "Xiao Universe" blog, make sure to keep this source http://5460095.blog.51cto.com/5450095/1758465

"You are now using this SocketAsyncEventArgs instance for asynchronous socket operations" processing

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.