在Windows Azure上部署Web套接字服务器 [英] Deploying Web Socket Server on Windows Azure

查看:133
本文介绍了在Windows Azure上部署Web套接字服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了本地运行,并利用我使用炼金术网络套接字实现一个简单的Web套接字服务器的简单Web应用程序。现在我需要部署这个应用程序到Windows Azure。

I have created a simple web application which runs locally and makes use of a simple web socket server which I implemented using Alchemy Web Sockets. Now I need to deploy this app to Windows Azure.

目前的解决方案是由一个MVC4网站和Web套接字服务器控制台应用程序。我的问题是如何将部署我目前的解决方案到Windows Azure?它甚至有可能使用Azure中的控制台应用程序?

Currently the solution is made up of an MVC4 website and a console app for the web socket server. My question is how would I deploy my current solution to Windows Azure? Is it even possible to use Azure for the console app?

这是我见过的Azure网站,我可以部署MVC4网站作为一个Azure的网站以及一个虚拟机或云服务上的控制台应用程序(服务器)上。在我看来,一个云服务更有意义(因为基础设施是由微软管理的,我不感兴趣),但我完全新的这些技术,所以我不知道这是最好的方法/如果是甚至有可能。

From what I've seen on the Azure website I can deploy the MVC4 website as an Azure website and the console app (server) on either a virtual machine or a cloud service. It seems to me that a cloud service makes more sense (since the infrastructure is managed by Microsoft and I am not interested in that), but I am completely new to these technologies so I am not sure which is the best approach/if it is even possible.

编辑:

我已经实现了网络套接字服务器控制台应用程序作为Web角色的一部分,由Sandrino的建议。但是,加载它连接到我得到以下错误在chrome调试服务器的页面时,意外的响应code:200

I have implemented the web socket server console app as part of the web role as suggested by Sandrino. However, when loading the page which connects to the server I get the following error in the chrome debugger Unexpected response code: 200 .

我已经离开一切,除了我使用相同的 @ HttpContext.Current.Request.ServerVariables [HTTP_HOST] 来连接到服务器上,因为不同的客户端服务器将在Azure中使用,我在本地的应用程序尝试这样做,它的工作。我还没有部署到Azure的,但我在本地测试,也许服务器没有实际运行,我怎么能检查这个?使用断点似乎正在进入启动服务器的必要方法。

I have left everything the same except that I use @HttpContext.Current.Request.ServerVariables["HTTP_HOST"] to connect to the server on the client side since different servers will be used in Azure, I have tried this in a local app and it worked. I still have not deployed to Azure but am testing locally, maybe the server is not actually running, how can I check this? Using breakpoints it seems that the necessary methods to start the server are being entered.

推荐答案

我建议你从你的控制台应用程序采取code和其移动到云服务的WebRole.cs。此文件是您的实例意味着你的code中的实例启动时运行的入口点。这将允许你在同一个角色的ASP.NET MVC应用程序一起运行WebSocket的服务器。

I suggest you take the code from your console application and move it to the WebRole.cs of your Cloud Service. This file is the entry point of your instance meaning your code will run when the instance starts. This will allow you to run the WebSocket server together with your ASP.NET MVC application in the same role.

因此​​,在Visual Studio中,你需要创建一个新的云服务,并选择一个MVC4 Web角色。

So in Visual Studio you'll need to create a new Cloud Service and choose an MVC4 Web Role.

public class WebRole : RoleEntryPoint
{
    public override bool OnStart()
    {
        Task.Factory.StartNew(OnStartWebSocketServer, TaskCreationOptions.LongRunning);
        return base.OnStart();
    }

    private void OnStartWebSocketServer()
    {
        var aServer = new WebSocketServer(81, IPAddress.Any)
        {
            OnReceive = OnReceive,
            OnSend = OnSend,
            OnConnect = OnConnect,
            OnConnected = OnConnected,
            OnDisconnect = OnDisconnect,
            TimeOut = new TimeSpan(0, 5, 0)
        };
        aServer.Start();
    }
}

这篇关于在Windows Azure上部署Web套接字服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆