github上下载.net 版本的NDde 开发包

 或者在此处下载开发包

MSDN 地址

 

创建服务器

    class BasicDDE:DdeServer
    {
        public BasicDDE(string ServiceName):base(ServiceName)
        {
        }
    }

在主类中

        private void MakeServer()
        {
            BasicDDE server = new BasicDDE("BasicDDE");
            server.Register();
        }

服务器的创建关键就是服务器名称。

创建客户端

        private void MakeClient(string ServiceName,string topic)
        {try
            {
                client = new DdeClient(ServiceName, topic,this);
                client.Connect();
            }
            catch (Exception)
            {
          client
= null; MessageBox.Show("DDE Client Creation failed"); } }

关键是对应的服务器名称和topic名称。

 

HotLink模式

类似于长连接,服务器可以主动推送相关信息给客户端。

这里的例子服务器开始定时器,每个一秒调用Advise函数

Advise("*", "*");
//向所有topic和item发送消息

发送的时候,会调用

        protected virtual byte[] OnAdvise(string topic, string item, int format);

发送具体信息。

服务器全部代码

    class BasicDDE:DdeServer
    {
        public System.Timers.Timer timer = new System.Timers.Timer();
        public BasicDDE(string ServiceName):base(ServiceName)
        {
            timer.Elapsed += timer_Elapsed;
            timer.Interval = 1000;
            timer.SynchronizingObject = this.Context;
        }

        void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            Advise("*", "*");
        }

        protected override byte[] OnAdvise(string topic, string item, int format)
        {
            return System.Text.Encoding.UTF8.GetBytes("Server Advise:" + DateTime.Now.ToString());
        }
    }
View Code

相关文章:

  • 2022-12-23
  • 2021-07-12
  • 2022-12-23
  • 2021-08-18
  • 2021-11-04
  • 2022-12-23
  • 2021-12-20
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-05-19
  • 2021-07-22
  • 2021-06-21
  • 2021-08-16
  • 2022-12-23
  • 2021-11-19
相关资源
相似解决方案