public void SendToClients(List <ServerClient> receiverList, DAbstract data) { foreach (ServerClient receiver in receiverList) { this.SendToClient(receiver, data); } }
internal void Send(DAbstract data) { if (this.Connected) { DNetworkPacket <DAbstract> networkPacket = new DNetworkPacket <DAbstract> { type = data.GetType().Name, data = data }; byte[] buffer = Encoding.ASCII.GetBytes(networkPacket.ToJson()); this.stream.Write(new byte[] { 0x69 }); this.stream.Write(BitConverter.GetBytes(buffer.Length)); this.stream.Write(new byte[] { new PacketFlags().Result() }); this.stream.Write(buffer); this.stream.Write(new byte[] { Utility.CalculateChecksum(buffer) }); this.stream.Flush(); } }
private void SendToClient(ServerClient receiver, DAbstract data) { if (this.disposed) { throw new ObjectDisposedException(nameof(Server)); } if (receiver != null && receiver.Connected) { receiver.Send(data); } }
public void Broadcast(DAbstract data) => this.SendToClients(this.ServerClientManager.ClientList, data);
} // use dynamic so you won't need to cast. Base type is always DAbstract // dynamic type can be found using BikeDataReceivedEventArgs.Type public BikeDataReceivedEventArgs(BikeDataType type, DAbstract data) { this.Type = type; this.Data = data; }
private void SendData(string id, DAbstract data = null) => this.SendData(new DVRClientPacket <DAbstract>() { id = id, data = data }.ToJson()); // Create VRClientPacket