chronoxor / CSharpServer

Ultra fast and low latency asynchronous socket server & client C# library with support TCP, SSL, UDP protocols and 10K connections problem solution
https://chronoxor.github.io/CSharpServer
MIT License
113 stars 32 forks source link

TcpChatServer Example - Get list of connected ChatSessions #6

Closed matthiasorth closed 4 years ago

matthiasorth commented 4 years ago

I'm looking for a way to get a list of connected ChatSessions in the ChatServer object. Something like this:

              foreach (ChatSession sess in server.ChatSessions) 
              {
                    sess.Send(GetNewMessageFor(sess.Id));
              }

Maybe someone can give a hint. Thanks a lot!

chronoxor commented 4 years ago

You have two options: 1) Use server.Multicast(...) method to send message to ALL connected sessions 2) You can override server.OnConnected()/server.OnDisconnected() methods in your code and handle sessions. Then you can use server.FindSession(id).Send(...) to send message to some session by its Id.

matthiasorth commented 4 years ago

Thanks a lot!

Best regards, Matthias

findli commented 2 years ago

You have two options:

  1. Use server.Multicast(...) method to send message to ALL connected sessions
  2. You can override server.OnConnected()/server.OnDisconnected() methods in your code and handle sessions. Then you can use server.FindSession(id).Send(...) to send message to some session by its Id.

Hi. Is there a way to get request headers from client( and add headers to initial client request)? Or somehow provide client identity from the client side during establish connection step?

It's only support in NetServer version?