NetCoreServer icon indicating copy to clipboard operation
NetCoreServer copied to clipboard

A SendAsync and Send is needed in Server Side

Open BlackCharon142 opened this issue 3 years ago • 1 comments

I know Multicast exists but I can't seem to find a built-in option to send a message in a specific chat server session currently, I have this solution right now but if it's an easy fix I would like to use that instead

class TCPServer : TcpServer
    {
        TCPSession session;

        public TCPServer(IPAddress address, int port) : base(address, port) { }

        protected override TcpSession CreateSession()
        {
            session = new TCPSession(this);
            return session;
        }

        public bool SendMessage(string message)
        {
            if (this.IsStarted)
            {
                try
                {
                    session.SendAsync(message);
                    return true;
                }
                catch
                { }
                return false;
            }
            return false;
        }

        protected override void OnError(SocketError error)
        {
            Console.Write($"TCP Server Connection to Client({Endpoint}) Encountered an Error : {error}");
        }
    }

BlackCharon142 avatar Aug 27 '22 18:08 BlackCharon142

What you need is public TcpSession FindSession(Guid id) in your TCPServer

chronoxor avatar Aug 28 '22 17:08 chronoxor