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); }
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; } }
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 }
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; } }
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; } }