Convert the following C# code into Silverlight 4/5??? RRS feed

  • Question

  • Hi,

    Could you please convert the following C# code into Silverlight 4/5 code:

    using System;
    using System.Net;
    using System.Net.Sockets;
    using System.Text.RegularExpressions;
    using System.Text;

    namespace AsteriskPrototype
    class AppConsole
    static void Main(string[] args)
    Console.WriteLine("Quick and Dirty Asterisk Manager Daemon Test:\n");

    // Connect to the asterisk server.
    Socket clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
    IPEndPoint serverEndPoint = new IPEndPoint(IPAddress.Parse(""), 5038);

    // Login to the server; manager.conf needs to be setup with matching credentials.
    clientSocket.Send(Encoding.ASCII.GetBytes("Action: Login\r\nUsername: mark\r\nSecret: mysecret\r\nActionID: 1\r\n\r\n"));

    int bytesRead = 0;

    byte[] buffer = new byte[1024];
    bytesRead = clientSocket.Receive(buffer);

    //Console.WriteLine(bytesRead + " bytes from asterisk server.");

    string response = Encoding.ASCII.GetString(buffer, 0, bytesRead);

    if(Regex.Match(response, "Message: Authentication accepted", RegexOptions.IgnoreCase).Success)
    // Send a ping request the asterisk server will send back a pong response.
    clientSocket.Send(Encoding.ASCII.GetBytes("Action: Ping\r\nActionID: 2\r\n\r\n"));
    }while(bytesRead != 0);

    Console.WriteLine("Connection to server lost.");
    Tuesday, January 10, 2012 5:53 AM

All replies