Skip to content

Instantly share code, notes, and snippets.

@SimonCropp
Created November 7, 2011 06:56
Show Gist options
  • Save SimonCropp/1344356 to your computer and use it in GitHub Desktop.
Save SimonCropp/1344356 to your computer and use it in GitHub Desktop.
multiport kayak
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