與眾不同windows phone (33)

來源:互聯網
上載者:User

Communication(通訊)之源特定組播 SSM(Source Specific Multicast)

樣本

1、服務端

Main.cs

/*    * 此服務會定時向指定的多播組發送訊息,用於示範 SSM    */       using System;   using System.Collections.Generic;   using System.ComponentModel;   using System.Data;   using System.Drawing;   using System.Linq;   using System.Text;   using System.Windows.Forms;          using System.Net;   using System.Net.Sockets;          namespace SocketServerSSM   {       public partial class Main : Form       {           System.Threading.SynchronizationContext _syncContext;                  public Main()           {               InitializeComponent();                      LaunchSocketUdp();           }                  private void LaunchSocketUdp()           {               _syncContext = System.Threading.SynchronizationContext.Current;                      // 定義 Source Specific Multicast 中的 Source,即 SSM 用戶端僅接收此 Source 發送到多播組的資料               IPEndPoint sourcePoint = new IPEndPoint(IPAddress.Any, 3370);                      // 定義多播組               IPEndPoint multicastPoint = new IPEndPoint(IPAddress.Parse("224.0.1.2"), 3369);                      UdpClient sourceUdp = new UdpClient(sourcePoint);               ShowMessage("用於示範 SSM 的 Socket 服務已啟動,每 3 秒向多播組發送一次資訊");                             // 每 3 秒向多播組發送一次資訊               var timer = new System.Timers.Timer();               timer.Interval = 3000d;               timer.Elapsed += delegate            {                   string msg = string.Format("{0} - {1}", Dns.GetHostName(), DateTime.Now.ToString("HH:mm:ss"));                   byte[] data = Encoding.UTF8.GetBytes(msg);                          sourceUdp.Send(data, data.Length, multicastPoint);               };               timer.Start();           }                  public void ShowMessage(string msg)           {               txtMsg.Text += msg + "\r\n";           }       }   }

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.