Run SuperSocket in Windows Azure

Windows Azure is Microsoft's cloud computing platform! Microsoft's Windows Azure provides on-demand computing power and storage capacity to host, scale and manage applications on the Internet to developers by it's data center.

The application running on Windows Azure has high reliability and scalability.

SuperSocket based server program can easily run on Windows Azure platform.

Different with normal SuperSocket server deployment, firstly, you need to set input endpoint in the page of the role property:


Then you need to fetch corresponding internal endpoint you can listen by you defined external endpoint:
var instanceEndpoint = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints[serverConfig.Name + "Endpoint"];

Full code listed below:
public override bool OnStart()
{
    LogUtil.Setup();

    // Set the maximum number of concurrent connections 
    ServicePointManager.DefaultConnectionLimit = 100;

    // see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357.
    var serverConfig = ConfigurationManager.GetSection("socketServer") as SocketServiceConfig; 

    if (!SocketServerManager.Initialize(serverConfig, ResolveServerConfig))
    {
        Trace.WriteLine("Failed to initialize SuperSocket!", "Error");
        return false;
    } 

    if (!SocketServerManager.Start())
    {
        Trace.WriteLine("Failed to start SuperSocket!", "Error");
        return false;
    }

    return base.OnStart();
}

private IServerConfig ResolveServerConfig(IServerConfig serverConfig)
{
    var config = new ServerConfig();
    serverConfig.CopyPropertiesTo(config); 

    var instanceEndpoint = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints[serverConfig.Name + "Endpoint"];

    if (instanceEndpoint == null)
    {
        Trace.WriteLine(string.Format("Failed to find Input Endpoint configuration {0}!", serverConfig.Name + "Endpoint"), "Error");
        return serverConfig;
    } 

    var ipEndpoint = instanceEndpoint.IPEndpoint;
    config.Ip = ipEndpoint.Address.ToString();
    config.Port = ipEndpoint.Port;
    return config;
}

In this way, your SuperSocket server program can run correctly in the Windows Azure platform.

Complete sample code, please refer to the source code WindowsAzure folder.

Last edited Jun 22, 2011 at 4:38 AM by kerryjiang, version 8

Comments

Robar Jul 27, 2012 at 9:48 AM 
Is there a easy way to add SSL/TLS encryption to the WebSocketServer in Windows Azure?