public void StartServer() { //Don't start server unless it is currently not started if (listener == null) { //Indicate that the server is currently enabled Settings.Default.ServerEnabled = true; //Start listener on the configured port listener = TcpListener.Create(Settings.Default.ServerPort); listener.Start(); var context = System.Threading.Thread.CurrentContext; //Listen for Tcp connections until server is disabled Observable.Start(() => { while(Settings.Default.ServerEnabled) { //Accept a client connection - blocking call var client = listener.AcceptTcpClient(); var stream = client.GetStream(); //Create a slippi connection object var connection = new SlippiConnection(client, stream); //Add slippi connection to collection, prep it to be removed if an error is encountered lock(syncLock) Connections.Add(connection); connection.TerminateAction = () => { lock (syncLock) Connections.Remove(connection); }; } }, System.Reactive.Concurrency.TaskPoolScheduler.Default); } }
public void StartServer() { //Don't start server unless it is currently not started if (listener == null) { //Indicate that the server is currently enabled Settings.Default.ServerEnabled = true; //Start listener on the configured port listener = TcpListener.Create(Settings.Default.ServerPort); listener.Start(); var context = System.Threading.Thread.CurrentContext; //Listen for Tcp connections until server is disabled Observable.Start(() => { while (Settings.Default.ServerEnabled) { //Accept a client connection - blocking call var client = listener.AcceptTcpClient(); var stream = client.GetStream(); //Create a slippi connection object var connection = new SlippiConnection(client, stream); //Add slippi connection to collection, prep it to be removed if an error is encountered lock (syncLock) Connections.Add(connection); connection.TerminateAction = () => { lock (syncLock) Connections.Remove(connection); }; } }, System.Reactive.Concurrency.TaskPoolScheduler.Default); } }