Azureエミュレーターを使用しています。worker ロールでポート 4702 をリッスンしたいと考えています。インスタンス数 = 1 の場合、例外はスローされません。ただし、インスタンス数を 2 に設定すると、ポート 4702 で 2 回 opent が試行され (run は 2 回起動されます)、例外がスローされます。 Azureのワーカーロールで着信接続を正しくリッスンする方法は?
InputEndpoint のタイプは「Input」です。構成:
<WorkerRole name="GpsRerouterWorker" vmsize="Small">
<Imports>
<Import moduleName="Diagnostics" />
</Imports>
<Endpoints>
<InputEndpoint name="reroutei4702" protocol="tcp" port="4702" localPort="4702" />
</Endpoints>
<LocalResources>
<LocalStorage name="DiagnosticStore" sizeInMB="20000" cleanOnRoleRecycle="false" />
</LocalResources>
</WorkerRole>
コード:
public class WorkerRole : RoleEntryPoint
{
public override void Run()
{
System.Net.IPEndPoint IPEndpoint = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["gpsreroutei4702"].IPEndpoint; TcpListener listener = new TcpListener(IPEndpoint);
listener.Start();
Logger.Log("Server is running");
while (true)
{
Logger.Log("Waiting for connections...");
try
{
var tcpClient = await listener.AcceptTcpClientAsync();
await HandleConnectionAsync(tcpClient);
}
catch (Exception exp)
{
Logger.Log(exp.ToString());
}
}
}
public override bool OnStart()
{
// Set the maximum number of concurrent connections
ServicePointManager.DefaultConnectionLimit = 12;
// For information on handling configuration changes
// see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357.
return base.OnStart();
}
}
UPD: コードを更新しました。今では動作します。