Example #1
0
 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;
 }
Example #2
0
 /// <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);
 }
Example #3
0
 protected override void OnSocketClosed(ChannelContext context, string remoteaddress)
 {
 }
Example #4
0
 /// <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();
     }
 }
Example #5
0
 protected abstract void OnSocketClosed(ChannelContext context, string remoteaddress);
Example #6
0
 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();
     }
 }