//网页上发送来的指令,都会被传到Notify函数中, 如需对网页上执行的命令进行限制, 可在Notify函数里手工加入判断限制代码。 #region IObserver Members public void Notify(object sender, string text) { if (InvokeRequired) { Invoke(new NotifyDelegate(Notify), sender, text); return; } richTextBox1.SelectionColor = Color.LimeGreen; richTextBox1.SelectionFont = new Font("宋体", 9); richTextBox1.AppendText("\r\n" + text); richTextBox1.AppendText("\r\n"); if (ec.m_ConnectionState == StateClass.ConnectionState.Logined) { remotableObject = (MyRemotableObject)sender; if (text.ToUpper().Trim().StartsWith("RT")) { //此构造函数可以提取团队中的姓名等特殊数据 RTWithNMAndPrice(text); } else if (text.ToUpper().Trim().StartsWith("AV")) { GetFlights(text); } } else { remotableObject = (MyRemotableObject)sender; remotableObject.ResultString = "服务器ETERM未登陆 或 执行了RT以外的指令\r\rCommand:" + text; remotableObject.Set(); } }
private List <string> messages = new List <string>(); // list of messages public RemoteServer() { remotableObject = new MyRemotableObject(); //************************************* TCP *************************************// // using TCP protocol TcpChannel channel = new TcpChannel(8080); ChannelServices.RegisterChannel(channel); // Show the name of the channel. Console.WriteLine("The name of the channel is {0}.", channel.ChannelName); RemotingConfiguration.RegisterWellKnownServiceType(typeof(MyRemotableObject), "RemoteChat", WellKnownObjectMode.Singleton); //************************************* TCP *************************************// Interface.Cache.Attach(this); }
/// <summary> /// Remote调用 /// </summary> /// <param name="Cmd"></param> /// <param name="timeout"></param> /// <param name="dtStr"></param> /// <returns></returns> public static string RemoteCmd(string url, string Cmd, int timeout, string dtStr) { string innerErrorMessage = string.Empty; string s = null; try { string httpChannelName = "remoting"; HttpClientChannel chan = (HttpClientChannel)ChannelServices.GetChannel(httpChannelName); if (chan == null) { chan = new HttpClientChannel(httpChannelName, null); IDictionary properties = new Hashtable(); properties["name"] = httpChannelName; properties["timeout"] = timeout; chan = new HttpClientChannel(properties, null); ChannelServices.RegisterChannel(chan, false); } // Create an instance of the remote object MyRemotableObject remoteObject = (MyRemotableObject)Activator.GetObject(typeof(MyRemotableObject), url); s = remoteObject.SetMessage(Cmd); } catch (Exception ex) { innerErrorMessage = string.Format("JetermClient.Common的RemoteCmd请求抛异常:{0}请求时间:{1}{0}请求url:{0}{2}{0}请求数据:{0}{3}{0}返回:{0}{4}{0}异常信息为:{0}{5}", Environment.NewLine, dtStr, url, Cmd, (string.IsNullOrWhiteSpace(s) ? "返回为空" : s), ex.ToString()); log.Error(innerErrorMessage); } if (!string.IsNullOrWhiteSpace(innerErrorMessage)) { throw new Exception(innerErrorMessage); } return(s); }
private void Login() { var host = (TextBox)this.FindName("host"); var port = (TextBox)this.FindName("port"); String uri = String.Concat("tcp://", host.Text, ":", port.Text, "/RemoteChat"); //************************************* TCP *************************************// // using TCP protocol // running both client and server on same machines chan = new TcpChannel(); ChannelServices.RegisterChannel(chan, false); // Create an instance of the remote object remoteObject = (MyRemotableObject)Activator.GetObject(typeof(MyRemotableObject), uri); //************************************* TCP *************************************// //create listen thread listenThread = new Thread(new ThreadStart(delegate() { Application app = System.Windows.Application.Current; for (;;) { app.Dispatcher.Invoke( System.Windows.Threading.DispatcherPriority.SystemIdle, new Action( delegate() { // get conversation and connected members from server this.setConversation(); this.setMembers(); } )); } })); listenThread.Start(); }