Created
November 7, 2011 06:56
-
-
Save SimonCropp/1344356 to your computer and use it in GitHub Desktop.
multiport kayak
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected override void OnStart(string[] args) | |
{ | |
var ports = new [] { 91, 8091 }; | |
foreach (var port in ports) | |
{ | |
try | |
{ | |
ListenOnThread(port); | |
} | |
catch(Exception exception) | |
{ | |
Logger.ErrorException(string.Format("Failed to listen on port {0}", port), exception); | |
} | |
} | |
} | |
private void ListenOnThread(int portNumber) | |
{ | |
//cause scheduler.Start() is a blocking call need to do on another thread | |
var thread = new Thread(() => | |
{ | |
var schedulerDelegate = new SchedulerDelegate | |
{ | |
Logger = Logger | |
}; | |
var scheduler = KayakScheduler.Factory.Create(schedulerDelegate); | |
var ipEndPoint = new IPEndPoint(IPAddress.Any, portNumber); | |
using (KayakServer.Factory.CreateGate(AppBuilder.BuildConfiguration(Startup.Configuration), scheduler, null).Listen(ipEndPoint)) | |
{ | |
scheduler.Start(); | |
} | |
}); | |
threads.Add(thread); | |
thread.Start(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment