using System; using System.IO; using System.Net; namespace Server.Net { public enum ChannelType { Connect, Accept, } public struct Packet { public const int MinPacketSize = MessageIndex + OpcodeLength; public const int ActorIdLength = 3; public const int OpcodeLength = 4; public const int MessageIndex = ActorIdLength + ActorIdLength; public ushort Opcode; public MemoryStream MemoryStream; } public struct RouterPacket { /// /// 总长度 /// public const int TotalLength = 4; /// /// 路由包长度 /// public const int RouterPacketLength = 4; /// /// 路由包长度索引 /// public const int RouterPacketLengthIndex = TotalLength; /// /// 路由包类型 /// public const int RouterPacketOpcode = 4; public const int RouterPacketOpcodeIndex = TotalLength + RouterPacketLength; public const int RouterPacketBodyIndex = TotalLength + RouterPacketLength + RouterPacketOpcode; /// /// 路由包数据的最小长度 /// public const int RouterPacketMinLength = TotalLength + RouterPacketLength + RouterPacketOpcode; /// /// 客户端包长度 /// public const int ClientPacketLength = 4; /// /// 客户端包类型 /// public const int ClientPacketOpcode = 4; } public abstract class AChannel : IDisposable { public long Id; public ChannelType ChannelType { get; protected set; } private IPEndPoint remoteAddress; public IPEndPoint RemoteAddress { get { return this.remoteAddress; } set { this.remoteAddress = value; } } public bool IsDisposed { get { return this.Id == 0; } } public abstract void Dispose(); } }