Exemplo n.º 1
0
        public void StartClient()
        {
            BinaryServerFormatterSinkProvider serverProvider = new BinaryServerFormatterSinkProvider();
            BinaryClientFormatterSinkProvider clientProvider = new BinaryClientFormatterSinkProvider();

            serverProvider.TypeFilterLevel = TypeFilterLevel.Full;

            IDictionary props = new Hashtable();

            props["port"] = 0;
            TcpChannel channel = new TcpChannel(props, clientProvider, serverProvider);

            ChannelServices.RegisterChannel(channel);

            // 由config中读取相关数据
            string broadCastObjURL = ConfigurationManager.AppSettings["BroadCastObjURL"];
            string upCastObjURL    = ConfigurationManager.AppSettings["RobotUpCastObjURL"];

            // 获取广播远程对象
            watch   = (IBroadCast)Activator.GetObject(typeof(IBroadCast), broadCastObjURL);
            wrapper = new EventWrapper();
            wrapper.LocalBroadCastEvent += new BroadCastEventHandler(broadCastHandler.OnBroadCastingInfo);
            watch.BroadCastEvent        += new BroadCastEventHandler(wrapper.BroadCasting);

            // upcast
            upCast = (IUpCast)Activator.GetObject(typeof(IUpCast), upCastObjURL);
        }
Exemplo n.º 2
0
        public void FinishClient()
        {
            if (CommState.GetState() == (int)VisCommState.StateEnum.Starting)
            {
                return;
            }

            try
            {
                // 卸载远程对象的事件函数
                watch.BroadCastEvent -= new BroadCastEventHandler(wrapper.BroadCasting);
                upCast = null;

                // 释放通道
                foreach (IChannel channel in ChannelServices.RegisteredChannels)
                {
                    ChannelServices.UnregisterChannel(channel);
                }

                visCommState.SetState((int)VisCommState.StateEnum.Finished);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Exemplo n.º 3
0
        private void SendToServerForm_Load(object sender, System.EventArgs e)
        {
            #region 客户端订阅客户端事件

            BinaryServerFormatterSinkProvider serverProvider = new BinaryServerFormatterSinkProvider();
            BinaryClientFormatterSinkProvider clientProvider = new BinaryClientFormatterSinkProvider();
            serverProvider.TypeFilterLevel = TypeFilterLevel.Full;
//
            IDictionary props = new Hashtable();
            props["port"] = 0;
            props["name"] = "ClientTcp";
            channel       = new TcpChannel(props, clientProvider, serverProvider);
            ChannelServices.RegisterChannel(channel);
//
//			bc = (IBroadCast)Activator.GetObject(
//				typeof(IBroadCast),"http://localhost:8086/BroadCastMessage.soap");

            //HttpChannel channel = new HttpChannel(1);
            //ChannelServices.RegisterChannel(channel);

            upCast = (IUpCast)Activator.GetObject(typeof(IUpCast), "tcp://localhost:8086/UpCastObj.soap");


            #endregion
        }
Exemplo n.º 4
0
        public void PauseClient()
        {
            if (CommState.GetState() == (int)VisCommState.StateEnum.Paused)
            {
                return;
            }

            try
            {
                // 卸载远程对象的事件函数
                watch.BroadCastEvent -= new BroadCastEventHandler(wrapper.BroadCasting);
                upCast = null;
                visCommState.SetState((int)VisCommState.StateEnum.Paused);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Exemplo n.º 5
0
        public void ResumeClient()
        {
            if (CommState.GetState() == (int)VisCommState.StateEnum.Running)
            {
                return;
            }

            string upCastObjURL = ConfigurationManager.AppSettings["VisUpCastObjURL"];

            try
            {
                //  重新注册远程对象的事件函数
                watch.BroadCastEvent += new BroadCastEventHandler(wrapper.BroadCasting);
                upCast = (IUpCast)Activator.GetObject(typeof(IUpCast), upCastObjURL);
                visCommState.SetState((int)VisCommState.StateEnum.Running);
            }
            catch (Exception ex)
            {
                throw;
            }
        }