SuperSocket 1.4 series documentation (17) Run SuperSocket in Windows Azure

Source: Internet
Author: User

Windows Azure is Microsoft's cloud computing platform! Windows Azure uses Microsoft's data center to provide developers with On-demand computing and storage capabilities to host, expand, and manage applications on the Internet.

Applications running on Windows Azure have high reliability and scalability.

SuperSocket-based server programs can run easily on the Windows Azure platform.

Unlike Common Socket server programs, you must first set the Socket program's external Endpoint in the Role attribute:

Then, dynamically obtain the internal Endpoint corresponding to the external Endpoint in the WorkerRole code file:

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

The complete code is as follows:

public override bool OnStart()

{

    LogUtil.Setup();

    // Set the maximum number of concurrent connections 

    ServicePointManager.DefaultConnectionLimit = 100;

 

    // For information on handling configuration changes

    // 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 on the Windows Azure platform.

For the complete sample code, see the project in the WindowsAzure folder in the source code.

Related Article

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.