I've been writing a socket server based around the one on CodeProject which itself derives from the original Microsoft example.
In both cases, the inbound message is immediately returned to the sender using the same SocketAsyncEventArgs. In my case, I need to send the inbound message off for further async processing prior to replying to the client.
The problem is that the returning response may try to use the same SocketAsyncEventArgs at the same time as a further message from the client. When this happens I get this exception:
"An asynchronous socket operation is already in progress using this SocketAsyncEventArgs instance"
So, (I believe) I need a separate pool of SocketAsyncEventArgs for messages going back out. All understandable so far.
My problem is that I'm not sure how to create the outbound SocketAsyncEventArgs as it relates closely to the inbound one.
How much of the inbound one can I reuse? e.g. If I just point at the same AcceptSocket, will there be trouble while messages travel in both directions simultaneously?
Does anyone have some example code of how to derive the outbound SocketAsyncEventArgs from the inbound one? Or am I missing the point?