Introduced
Silverlight 4.0 support for UDP protocols:
* Udpsinglesourcemulticastclient-a client that receives multicast information from a single source, the SSM client
Online Demo
Http://www.cnblogs.com/webabcd/archive/2010/08/09/1795417.html
Example
Demonstrates how to implement the SSM through Udpsinglesourcemulticastclient
1. Service End
Form1.cs
Code
Start the Socket service (based on UDP protocol) for demonstrating the SSM
private void Launchsocketudp ()
{
Service-Side IPEndPoint
IPEndPoint serverpoint = new IPEndPoint (Ipaddress.any, 3004);
IPEndPoint of broadcast address (255.255.255.255)
IPEndPoint broadcastpoint = new IPEndPoint (Ipaddress.broadcast, 3003);
Create a server-side UDP object based on the ipendpoint of the service side
UdpClient serverudp = new UdpClient (serverpoint);
ShowMessage ("The Socket Service for the demo SSM has started (based on UDP Protocol)");
Broadcast once per 3 table
var timer = new System.Timers.Timer ();
Timer. Interval = 3000d;
Timer. Elapsed + + Delegate
{
String msg = string. Format ("{0}: {1}-[{2}]", Dns.gethostname (), "Broadcast content", DateTime.Now.ToString ("HH:mm:ss"));
byte[] data = Encoding.UTF8.GetBytes (msg);
Send broadcast (specify separately: broadcast content; bytes of broadcast content; IPEndPoint of broadcast address)
Serverudp.send (data, data.) Length, Broadcastpoint);
};
Timer. Start ();
Receive information sent by client
var thread = new System.Threading.Thread (() =>
{
while (true)
{
IPEndPoint clientpoint = null;
Receives the information from the client and obtains the client's IPEndPoint
byte[] Receivedbytes = serverudp.receive (ref clientpoint);
String receiveddata = Encoding.UTF8.GetString (receivedbytes);
String message = String. Format ("{0}-from: {1}", Receiveddata, Clientpoint.tostring ());
_synccontext.post (Delegate {showmessage (message);}, NULL);
}
});
Thread. Start ();
}
To start the Multicast Security Policy Service
private void Launchmulticastpolicyserver ()
{
/*
* Before the Silverlight program joins a multicast group, the initial message is sent to the multicast group via UDP Port 9430, and then the server returns the appropriate security policy (see documentation)
* To facilitate the issuance of security policy, you can refer to the Microsoft.Silverlight.PolicyServers.dll assembly, which encapsulates the relevant methods
*/
The security policy configuration result of this example is: Authorization via UDP port 3003 to ask multicast group 224.0.0.1, authorization through UDP port 3006 ask multicast group 224.0.0.1
multicastpolicyconfiguration config = new multicastpolicyconfiguration ();
Config. Singlesourceconfiguration.add ("*", New Multicastresource (Ipaddress.parse ("224.0.0.1"), 3003); Configuring the SSM Security Policy
Multicastpolicyserver Server = new Multicastpolicyserver (config);
Server. Start ();
ShowMessage ("Multicast security Policy Service started");
}