public MessageListener(string fromIP, int fromPort, IMessageListenerCallBack innerListener)
 {
     this.FromIP    = fromIP;
     this.FromPort  = fromPort;
     this.AtTime    = DateTime.Now;
     _innerListener = innerListener;
 }
Esempio n. 2
0
        /// <summary>
        /// 注销;
        /// </summary>
        public void Unregist()
        {
            RemoteEndpointMessageProperty remoteEndpointProp = GetRemoteEndpointProp();
            IMessageListenerCallBack      callback           = OperationContext.Current.GetCallbackChannel <IMessageListenerCallBack>();

            MessageCenter.Instance.RemoveListener(new MessageListener(remoteEndpointProp.Address, remoteEndpointProp.Port, callback));
        }
Esempio n. 3
0
        public string OnRequest(string message)
        {
            //Console.WriteLine("OnRequest begin..");
            RemoteEndpointMessageProperty remoteEndpointProp = GetRemoteEndpointProp();
            IMessageListenerCallBack      callback           = OperationContext.Current.GetCallbackChannel <IMessageListenerCallBack>();

            return(MessageCenter.Instance.RequestMessage(new MessageListener(remoteEndpointProp.Address, remoteEndpointProp.Port, callback, 999, message)));
        }
Esempio n. 4
0
        /// <summary>
        /// 接受消息
        /// </summary>
        /// <param name="id">消息编号</param>
        /// <param name="message">消息内容</param>
        public void OnAccept(int id, string message)
        {
            //Console.WriteLine("OnAccept:id:{0},message:{1}",id,message);
            RemoteEndpointMessageProperty remoteEndpointProp = GetRemoteEndpointProp();
            IMessageListenerCallBack      callback           = OperationContext.Current.GetCallbackChannel <IMessageListenerCallBack>();

            MessageCenter.Instance.AcceptMessage(new MessageListener(remoteEndpointProp.Address, remoteEndpointProp.Port, callback, id, message));
        }
 public MessageListener(string fromIP, int fromPort, IMessageListenerCallBack innerListener, int id, string message)
 {
     this.FromIP      = fromIP;
     this.FromPort    = fromPort;
     this.FromMessage = message;
     this.MessageID   = id;
     this.AtTime      = DateTime.Now;
     _innerListener   = innerListener;
 }
Esempio n. 6
0
        /// <summary>
        /// 快速注册
        /// </summary>
        /// <param name="indentity">客户端标识</param>
        public void QuikRegist(string indentity)
        {
            RemoteEndpointMessageProperty remoteEndpointProp = GetRemoteEndpointProp();
            IMessageListenerCallBack      callback           = OperationContext.Current.GetCallbackChannel <IMessageListenerCallBack>();

            MessageCenter.Instance.AddListener(new MessageListener(remoteEndpointProp.Address, remoteEndpointProp.Port, callback), indentity);
            //Console.WriteLine("QuikRegist ok..");
            OperationContext.Current.Channel.Closing += new EventHandler(MessageCenter.Instance.Channel_Closing);
        }
Esempio n. 7
0
        /// <summary>
        /// 注册;
        /// </summary>
        public void Regist()
        {
            RemoteEndpointMessageProperty remoteEndpointProp = GetRemoteEndpointProp();
            IMessageListenerCallBack      callback           = OperationContext.Current.GetCallbackChannel <IMessageListenerCallBack>();

            MessageCenter.Instance.AddListener(new MessageListener(remoteEndpointProp.Address, remoteEndpointProp.Port, callback));
            //下面的事件在mono 无效
            OperationContext.Current.Channel.Closing += new EventHandler(MessageCenter.Instance.Channel_Closing);
            //Channel.Closing 参考 http://bbs.csdn.net/topics/390272596
            //Console.WriteLine("Regist ok.");
        }
Esempio n. 8
0
 /// <summary>
 /// 通道关闭事件处理程序
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 public void Channel_Closing(object sender, EventArgs e)
 {
     lock (_syncLock)
     {
         IMessageListenerCallBack clientCallback = (IMessageListenerCallBack)sender;
         var messageListener = _listeners.Find(p => p.GetListener() == clientCallback);
         if (messageListener != null)
         {
             RemoveListener(messageListener);
             Console.WriteLine("Channel_Closing");
         }
     }
 }