2010-05-30 22 views

回答

2

很容易在工作者角色上運行套接字服務器,但只能使用tcp,而不能使用udp。您可以從工作角色的OnStart()方法啓動您自己的進程您也可以使用Run()方法執行該進程,但是一旦您進入運行狀態,負載平衡器和外部世界就會看到您的角色,因此您可能會得到tcp您的套接字服務器運行之前的流量。

你需要在你的Worker角色的配置來創建一個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!"); 
+0

謝謝。我看到有投票的UDP已經:http://www.mygreatwindowsazureidea.com/forums/34192-windows-azure-feature-voting/suggestions/400782-udp-endpoints。 你知道我是否可以在這個過程中託管一個CLR? – bertelmonster2k 2010-05-30 16:13:15