云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > SuperSocket学习进展

SuperSocket学习进展

  • 62 次阅读
  • 3 次下载
  • 2025/5/1 21:51:48

在 Windows Azure 中运行SuperSocket

关键字: Windows Azure, WorkRole, InputEndPoint, 云计算, 微软云

什么是 Windows Azure?

Windows Azure 是微软的云计算平台!微软的Windows Azure通过它的数据中心提供了按需分配的计算能力和存储空间用于在互联网上托管,扩展和管理应用程序。

这些在 Windows Azure 上运行的应用有很高的可靠性和可扩展能力。基于SuperSocket开发的服务器程序一样也能够很方便的运行在 Windows Azure 平台上。

SuperSocket 配置

用于在 Windows Azure 上运行的配置文件 app.config 和直接运行的SuperSocket的配置文件相同。

type=\SuperSocket.SocketEngine\

type=\SuperSocket.QuickStart.RemoteProcessService\

添加SuperSocket的启动代码到 Windows Azure 的 WorkRole 项目

与其它SuperSocket程序相同,启动代码同样也要写到程序的入口处,如 Windows Azure 的 WorkRole 项目的OnStart() 方法: public override bool OnStart() {

// 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.

m_Bootstrap = BootstrapFactory.CreateBootstrap();

if (!m_Bootstrap.Initialize()) {

Trace.WriteLine(\ return false; }

var result = m_Bootstrap.Start();

switch (result) {

case (StartResult.None):

Trace.WriteLine(\configuration!\

return false;

case (StartResult.Success):

Trace.WriteLine(\ break;

case (StartResult.Failed):

Trace.WriteLine(\to start SuperSocket server! Please check error log for more information!\ return false;

case (StartResult.PartialSuccess):

Trace.WriteLine(\server instances were started successfully, but the others failed to start! Please check error log for more information!\ break;

}

return base.OnStart(); }

配置和使用 Input Endpoint

由于Windows Azure的内部网络架构,你不能直接监听你配置中的IP和端口。在这种情况下,你需要在Windows Azure项目中配置Input Endpoint:

这些 endpoint的命名规则是 \。 例如,我们在配置文件中配置了名为\的server:

然后我们就应该创建一个名为\的Endpoint。 在代码中,你可以通过编程的方式获得该Endpoint真正的端口号: var instanceEndpoint =

RoleEnvironment.CurrentRoleInstance.InstanceEndpoints[serverConfig.Name + \serverConfig.Port].Port;

但是你不用为SuperSocket这样做,因为 SuperSocket 已经实现了监听Endpoint的替换已经。 因此,你只需当SuperSocket的Bootstrap初始化的时候将Endpoint的字典传入就行了,最终代码如下:

public override bool OnStart() {

// 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. m_Bootstrap = BootstrapFactory.CreateBootstrap(); if (!m_Bootstrap.Initialize(RoleEnvironment.CurrentRoleInstance.InstanceEndpoints.ToDictionary(p => p.Key, p => p.Value.IPEndpoint))) { Trace.WriteLine(\ return false; } var result = m_Bootstrap.Start(); switch (result) { case (StartResult.None): Trace.WriteLine(\configuration!\ return false; case (StartResult.Success): Trace.WriteLine(\ break; case (StartResult.Failed): Trace.WriteLine(\to start SuperSocket server! Please check error log for more information!\ return false; case (StartResult.PartialSuccess): Trace.WriteLine(\the others failed to start! Please check error log for more information!\ break; } return base.OnStart(); } 最后,你就可以启动你的Windows Azure实例了。

搜索更多关于: SuperSocket学习进展 的文档
  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

在 Windows Azure 中运行SuperSocket 关键字: Windows Azure, WorkRole, InputEndPoint, 云计算, 微软云 什么是 Windows Azure? Windows Azure 是微软的云计算平台!微软的Windows Azure通过它的数据中心提供了按需分配的计算能力和存储空间用于在互联网上托管,扩展和管理应用程序。 这些在 Windows Azure 上运行的应用有很高的可靠性和可扩展能力。基于SuperSocket开发的服务器程序一样也能够很方便的运行在 Windows Azure 平台上。 SuperSocket 配置 用于在 Windows Azure 上运行的配置文件 app.config 和直接运行的SuperSocket的配置文

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com