NetCoreServer
NetCoreServer copied to clipboard
A SendAsync and Send is needed in Server Side
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}");
}
}
What you need is public TcpSession FindSession(Guid id) in your TCPServer