void HandleClient(AutoCADProcessor processor) { Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; try { while (true) { while (!ed.IsQuiescent) { Thread.Sleep(10); } if (!processor.ReadAndExecute()) { break; } } WriteMessage("Client disconnected\n"); } catch (IOException) { WriteMessage("Disconneting from client\n"); } catch (System.Exception e) { WriteMessage(e.ToString() + "\n"); WriteMessage("Terminating client\n"); } }
void WaitForConnections() { try { if (server == null) { Int32 port = 11000; IPAddress localAddr = IPAddress.Parse("127.0.0.1"); server = new TcpListener(localAddr, port); } else { server.Stop(); } server.Start(); WriteMessage("Waiting for connections\n"); while (true) { AutoCADProcessor processor = new AutoCADProcessor( syncCtrl, new Channel(server.AcceptTcpClient().GetStream()), new Primitives()); WriteMessage("Connection established\n"); Thread thread = new Thread(() => HandleClient(processor)); thread.Start(); } } catch (System.Exception e) { WriteMessage(e.ToString() + "\n"); } }