Azure 和本机代码

发布于 2024-09-03 16:00:21 字数 221 浏览 3 评论 0原文

看起来您可以在 Azure 上托管本机代码: http://msdn.microsoft .com/en-us/library/dd573362.aspx。是否可以在这里运行套接字服务器(侦听 tcp/udp)?甚至在上面托管一个 CLR?

It looks like you can host native code on Azure: http://msdn.microsoft.com/en-us/library/dd573362.aspx. Is it possible to run a socket server (listening tcp/udp) here? And even hosting a CLR on top?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

黯淡〆 2024-09-10 16:00:21

在辅助角色上运行套接字服务器很容易,但只能运行 tcp,不能运行 udp。您可以从辅助角色的 OnStart() 方法启动自己的进程,也可以从 Run() 方法执行此操作,但是一旦进入运行状态,负载均衡器和外界就会看到您的角色,因此您可能会获得 tcp套接字服务器运行之前的流量。

您需要在辅助角色的配置中创建一个 tcp 端点(右键单击辅助角色并查看“属性”):

alt text

您指定的端口号用于外部世界。负载均衡器将为您的每个角色实例提供一个您的代码将绑定到的唯一端口。例如,假设您的 MyApp.exe 在启动时采用 --tcpport 参数:

        var rootDirectory = Path.Combine(Environment.GetEnvironmentVariable("RoleRoot") + "\\", "approot\\MyApp");
        int port = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["MyExternalEndpoint"].IPEndpoint.Port;
        var cmdline = String.Format("--tcpport {0}",port);
        MyProcess = new Process()
            {
                StartInfo = new ProcessStartInfo(Path.Combine(rootDirectory, "myapp.exe"), cmdline)
                {
                    UseShellExecute = false,
                    WorkingDirectory = rootDirectory
                }
            };
            MyProcess.Start();

然后在您的 Run() 方法中,只需永远等待,知道您永远不应该退出:

MyProcess.WaitForExit();
throw new Exception("MyApp quit on me!");

It's easy to run a socket server on a worker role, but only tcp, not udp. You can start your own process from the worker role's OnStart() method You can do it from the Run() method too but once you hit the run state, your role is seen by the load balancer and outside world, so you might get tcp traffic before your socket server is running.

You'll need to create a tcp endpoint in your worker role's configuration (right-click the worker role and view Properties):

alt text

That port number you specify is for the outside world. The load balancer will give each of your role's instances a unique port that your code will bind to. For example, imagine your MyApp.exe that takes a --tcpport parameter on startup:

        var rootDirectory = Path.Combine(Environment.GetEnvironmentVariable("RoleRoot") + "\\", "approot\\MyApp");
        int port = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["MyExternalEndpoint"].IPEndpoint.Port;
        var cmdline = String.Format("--tcpport {0}",port);
        MyProcess = new Process()
            {
                StartInfo = new ProcessStartInfo(Path.Combine(rootDirectory, "myapp.exe"), cmdline)
                {
                    UseShellExecute = false,
                    WorkingDirectory = rootDirectory
                }
            };
            MyProcess.Start();

Then in your Run() method, simply wait forever, knowing you should never exit:

MyProcess.WaitForExit();
throw new Exception("MyApp quit on me!");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文