static void Listen(IAsyncResult ar) { try { Socket skt = svrSkt.EndAccept(ar); svrSkt.BeginAccept(Listen, null); var psr = new ClientProcessor(skt); processors.Add(psr); psr.BeginProcess(); } catch (ObjectDisposedException) { } }
static void Listen(IAsyncResult ar) { Socket skt = null; try { skt = svrSkt.EndAccept(ar); } catch (ObjectDisposedException) { } try { svrSkt.BeginAccept(Listen, null); } catch (ObjectDisposedException) { } if (skt != null) { var psr = new ClientProcessor(skt); psr.BeginProcess(); } }
public void Read(ClientProcessor psr, byte[] body, int len) { Read(psr, new NReader(new MemoryStream(Crypt(psr, body, len)))); }
public abstract byte[] Crypt(ClientProcessor psr, byte[] dat, int len);
protected override void Write(ClientProcessor psr, NWriter wtr) { }
protected override void Read(ClientProcessor psr, NReader rdr) { }
public override byte[] Crypt(ClientProcessor psr, byte[] dat, int len) { return dat; }
protected abstract void Write(ClientProcessor psr, NWriter wtr);
protected abstract void Read(ClientProcessor psr, NReader rdr);
public byte[] Write(ClientProcessor psr) { MemoryStream s = new MemoryStream(); this.Write(psr, new NWriter(s)); byte[] content = s.ToArray(); byte[] ret = new byte[5 + content.Length]; content = this.Crypt(psr, content, content.Length); Buffer.BlockCopy(BitConverter.GetBytes(IPAddress.HostToNetworkOrder(ret.Length)), 0, ret, 0, 4); ret[4] = (byte)this.ID; Buffer.BlockCopy(content, 0, ret, 5, content.Length); return ret; }