M
m00n
Guest
I'm trying to change my TCP/IP media streaming app from accepting only 1 client to multiple. I have these two functions
private TcpListener _tcpListener;
private List<TcpClient> _clientList;
public void StartServer( )
{
_tcpListener.Start( );
_tcpListener.BeginAcceptTcpClient( new AsyncCallback( ClientConnected ), null );
}
/// <summary>
/// Call back when a client connects to the server
/// </summary>
/// <param name="AR"></param>
public void ClientConnected( IAsyncResult AR )
{
TcpClient client = _tcpListener.EndAcceptTcpClient( AR );
_networkStream = _tcpClient.GetStream( );
_clientList.Add( client );
_tcpListener.BeginAcceptTcpClient( new AsyncCallback( ClientConnected ), null );
}
Where _tcpListener and _clientList are global to my class.
I have another function where I'm sending an image to a single client. But as mentioned, I'm trying to extend this to now service multiple clients.
Is it safe to say, that in my function where I'm sending my image to the client, if I want to send multiple clients the exact same image, I would have to iterate over every client in the List<TcpClient> list, get it's "NetworkStream" object and call it's send method? Or is there a simpler approach? One that does not seem like it would have so much overhead?
Rick
Continue reading...
private TcpListener _tcpListener;
private List<TcpClient> _clientList;
public void StartServer( )
{
_tcpListener.Start( );
_tcpListener.BeginAcceptTcpClient( new AsyncCallback( ClientConnected ), null );
}
/// <summary>
/// Call back when a client connects to the server
/// </summary>
/// <param name="AR"></param>
public void ClientConnected( IAsyncResult AR )
{
TcpClient client = _tcpListener.EndAcceptTcpClient( AR );
_networkStream = _tcpClient.GetStream( );
_clientList.Add( client );
_tcpListener.BeginAcceptTcpClient( new AsyncCallback( ClientConnected ), null );
}
Where _tcpListener and _clientList are global to my class.
I have another function where I'm sending an image to a single client. But as mentioned, I'm trying to extend this to now service multiple clients.
Is it safe to say, that in my function where I'm sending my image to the client, if I want to send multiple clients the exact same image, I would have to iterate over every client in the List<TcpClient> list, get it's "NetworkStream" object and call it's send method? Or is there a simpler approach? One that does not seem like it would have so much overhead?
Rick
Continue reading...