public void SendProtocol(IProtocol protocol, string to) { var message = protocol.GetBytes(); switch (protocol.Header) { case HeaderType.Time: _tcpClient?.Send(message); break; case HeaderType.Discover: _discoveryClients.ForEach(client => client.Send(message, to)); break; default: throw new ArgumentOutOfRangeException(); } }
public void SendProtocol(IProtocol protocol, IPEndPoint from, string to) { if (protocol.Action != ActionType.Response) { return; } var bytes = protocol.GetBytes(); AbstractServer server = protocol.Header switch { HeaderType.Discover => _multicastBroadcastServers.First(multicastServer => multicastServer.EndPoint.Equals(from)), HeaderType.Time => _tcpServers.First(multithreadingServer => multithreadingServer.EndPoint.Equals(from)), _ => throw new ArgumentOutOfRangeException() }; server.Send(bytes, to); }