/// <summary> /// /// </summary> internal void Init() { _context = new ChannelContext(); if (OnRequested != null) { _context.OnRequested += new RequestHandle(OnRequested); } if (OnCallRemote != null) { _context.OnCallRemote += new CallRemoteHandle(OnCallRemote); } if (OnClosing != null) { _context.OnClosed += new ClosingHandle(OnClosing); } if (OnSocketClosed != null) { _context.OnSocketClosed += new ClosingHandle(OnSocketClosed); } }
private bool NotifyChannelReceive(ChannelContext context, string param, byte[] buffer) { //并发 lock (_instance) { if (context != null && context.IsConnect) { try { var callback = context.GetCallback(); if (callback == null) { return false; } callback.Receive(param, buffer); return true; } catch (Exception ex) { context.IsClosed = true; TraceLog.WriteError("Notify:{0} {1}", param, ex); } } } return false; }
/// <summary> /// /// </summary> internal void Init() { _context = new ChannelContext(); if (OnRequested != null) _context.OnRequested += new RequestHandle(OnRequested); if (OnCallRemote != null) _context.OnCallRemote += new CallRemoteHandle(OnCallRemote); if (OnClosing != null) _context.OnClosed += new ClosingHandle(OnClosing); if (OnSocketClosed != null) _context.OnSocketClosed += new ClosingHandle(OnSocketClosed); }
protected override void OnSocketClosed(ChannelContext context, string remoteaddress) { }
/// <summary> /// /// </summary> /// <param name="context"></param> /// <param name="param"></param> /// <param name="remoteAddress"></param> /// <returns></returns> private byte[] OnRequestComplated(ChannelContext context, string param, string remoteAddress) { lock (context) { SocketGameResponse response = new SocketGameResponse(); HttpGet httpGet = new HttpGet(param, remoteAddress); OnRequested(httpGet, response); return response.ReadByte(); } }
protected abstract void OnSocketClosed(ChannelContext context, string remoteaddress);
protected byte[] OnCallRemoteComplated(ChannelContext context, string route, string param, string remoteAddress) { lock (context) { HttpGet httpGet = new HttpGet(param, remoteAddress); MessageStructure structure = new MessageStructure(); MessageHead head = new MessageHead(); OnCallRemote(route, httpGet, head, structure); structure.WriteBuffer(head); return structure.ReadBuffer(); } }