Slow and steady Silverlight (54)

Source: Internet
Author: User
Tags config silverlight

Introduced

Silverlight 4.0 support for UDP protocols:

* Udpanysourcemulticastclient-A client that sends information to a multicast group and receives multicast information from any source, that is, the ASM client

Online Demo

Http://www.cnblogs.com/webabcd/archive/2010/08/09/1795417.html

Example

Demonstrates how to implement ASM through Udpanysourcemulticastclient

1. Service End

Form1.cs

Code

// 启动多播的安全策略服务
private void LaunchMulticastPolicyServer()
{
    /*
     * Silverlight 程序加入多播组之前,会通过 UDP 端口 9430 发送初始消息到多播组,然后服务端返回相应的安全策略(详见文档)
     * 为了方便下发安全策略,可以引用 Microsoft.Silverlight.PolicyServers.dll 程序集,其封装了相关的方法
     */

    // 本例的安全策略配置结果为:授权通过 UDP 端口 3003 问多播组 224.0.0.1,授权通过 UDP 端口 3006 问多播组 224.0.0.1
    MulticastPolicyConfiguration config = new MulticastPolicyConfiguration();
    config.AnySourceConfiguration.Add("*", new MulticastResource(IPAddress.Parse("224.0.0.1"), 3006)); // 配置 ASM 的安全策略

    MulticastPolicyServer server = new MulticastPolicyServer(config);
    server.Start();

    ShowMessage("多播的安全策略服务已启动");
}

2. Client

UdpPacketEventArgs.cs

Code

using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace Silverlight40.Communication
{
    public class UdpPacketEventArgs : EventArgs
    {
        // UDP 包的内容
        public string Message { get; set; }
        // UDP 包的来源的 IPEndPoint
        public IPEndPoint Source { get; set; }

        public UdpPacketEventArgs(byte[] data, IPEndPoint source)
        {
            this.Message = System.Text.Encoding.UTF8.GetString(data, 0, data.Length);
            this.Source = source;
        }
    }
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.