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.