/// <summary> /// Begin async write from client /// </summary> /// <param name="src">Receiver's Id</param> /// <param name="ct">NetPacket command type</param> /// <param name="data">Data bytes</param> public void BeginWriteToClient(int src, NetPacket.PacketType ct, byte[] data) { NetPacket packet = new NetPacket(src, this._clientId, ct, data); Thread t = new Thread(this.StartWriteSync); t.Name = "ServerStartWriteSync"; t.Start(packet); }
/// <summary> /// Constructor /// </summary> /// <param name="endPoint">Specifies endpoint of sender</param> /// <param name="msg">Message associated with event</param> /// <param name="_packet">Packet received</param> /// <param name="exception">Any exception, if occured</param> public NetEventArgs(EndPoint endPoint, string msg, NetPacket _packet, Exception exception) { this._endPoint = endPoint; this._msg = msg; this._packet = _packet; this._exception = exception; }
/// <summary> /// Constructor /// </summary> /// <param name="_packet">Packet received</param> public NetEventArgs(NetPacket packet) : this(null, null, packet, null) { }
/// <summary> /// Constructor /// </summary> /// <param name="msg">Message associated with event</param> /// <param name="_packet">Packet received</param> public NetEventArgs(NetPacket packet, string msg) : this(packet) { this._msg = msg; }
/// <summary> /// Constructor /// </summary> /// <param name="endPoint">Specifies endpoint of sender</param> /// <param name="msg">Message associated with event</param> /// <param name="_packet">Packet received</param> public NetEventArgs(EndPoint endPoint, string msg, NetPacket packet) : this(endPoint, msg) { this._packet = packet; }
/// <summary> /// Deserialize NetPacket /// </summary> /// <param name="obj">Data bytes</param> private void UnsealPacket(object obj) { NetPacket packet = new NetPacket(); packet.Deserialize(obj as byte[]); switch (packet.Header.Type) { case NetPacket.PacketType.Command: this.ParseCommand(packet.Data); break; default: if (this.OnClientDataReceived != null) { NetEventArgs e = new NetEventArgs(packet); this.OnClientDataReceived(this._tcpClient, e); } break; } }
/// <summary> /// Gets the sender's name from the network packet by referecing the name table /// </summary> /// <param name="packet">NetPacket containing the header</param> /// <returns>Sender's name</returns> public string GetSenderName(NetPacket packet) { return this._clientNames[packet.Header.Source]; }
/// <summary> /// Gets the receiver's name from the network packet by referecing the name table /// </summary> /// <param name="packet">NetPacket containing the header</param> /// <returns>Sender's name</returns> public string GetReceiverName(NetPacket packet) { return this._clientNames[packet.Header.Destination]; }
/// <summary> /// Performs a write to client using the service of client manager /// </summary> /// <param name="dest">Client Id</param> /// <param name="ct">NetPacket command type</param> /// <param name="data">Data bytes</param> public void BeginWriteToClient(int dest, NetPacket.PacketType ct, byte[] data) { this._clientManager[dest].BeginWriteToClient(0, ct, data); }
public void BeginWriteToClient(int dest, NetPacket.PacketType ct, byte[] data) { NetPacket packet = new NetPacket(this._id, dest, ct, data); Thread t = new Thread(this.StartWriteSync); t.Name = "StartWriteSync"; t.Start(packet); }