Reputation: 1291
I followed link to create an Async TCP server. However, all examples cover only sending data as a response to receive. My question is how to Push data to a certain TCP client.
Let us say tat a byte[] needs to be sent/pushed to client Id 1. How can I achieve this using SocketAsyncEventArgs architecture?
I know I have to keep a list of active connections and client ids. What should this list look like in order to push data?
public bool Send(Socket socket, byte[] message)
{
SocketAsyncEventArgs completeArgs = new SocketAsyncEventArgs();
if (socket.Connected)
{
// Prepare arguments for send/receive operation.
completeArgs.SetBuffer(message, 0, message.Length);
completeArgs.UserToken = socket;
completeArgs.AcceptSocket = socket;
completeArgs.Completed += new EventHandler<SocketAsyncEventArgs>(OnIOCompleted);
// Start sending asyncronally.
socket.SendAsync(completeArgs);
}
return true;
}
Upvotes: 1
Views: 707