zoukankan      html  css  js  c++  java
  • SuperSocket 1.4系列文档(17) 在Windows Azure中运行SuperSocket

    Windows Azure是微软的云计算平台!Windows Azure通过微软的数据中心为开发人员提供以按需的计算能力和存储能力去托管、扩展和管理互联网上的应用程序。

    运行于Windows Azure上的应用程序具有很高的可靠性和可伸缩性。

    基于SuperSocket的服务器程序可以轻易的运行于Windows Azure平台之上。

    和普通Socket服务器程序不同,首先需要在Role的属性中设置Socket程序对外提供服务的Endpoint:

    M[90I@W~C78O1JN{4D@S@$9[4]

    然后在WorkerRole代码文件中动态的获取外部Endpoint所对应的内部Endpoint:

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

    完整的代码如下:

    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;
    }

    就这样,你的SuperSocket服务器程序就可以正确的运行在Windows Azure平台之上。

    完整的示例代码,请参考源代码中WindowsAzure文件夹下的项目。

    作者:江振宇
    出处:http://jzywh.cnblogs.com
    本文版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接,否则保留追究法律责任的权利。
  • 相关阅读:
    【Python】【文件】查找指定路径中是否存在目标文件(含此路径下的子文件夹)
    时隔一年的2020noip
    nacos 笔记
    webflux 小例子
    spring Initializr 笔记
    临时~spring启动过程
    Mac通过crontab设置定时任务报错Operation not permitted
    Isolation Forest Implementation(孤立森林)
    let arr=['a'] JSON.stringify(arr) 输出:“['a']” let arr2 = “['a']” JSON.parse(arr2) 输出: ['a']
    js对象中key值加引号和不加引号的区别
  • 原文地址:https://www.cnblogs.com/jzywh/p/2048131.html
Copyright © 2011-2022 走看看