/** * This class implements a simple concurrent TCP Echo server. * Read carefully through the comments below. */ public static void Main(string[] args) { var server = new Server(5.0f, true); server.StartListening(); while (true) { server.AcceptClients(); // accept new clients server.ProcessQueue(); // process queued messages server.ProcessClients(); // process clients for new messages server.CleanupClients(); // remove faulty/disconnected clients Thread.Sleep(25); } }
private void connectToolStripMenuItem_Click(object sender, EventArgs e) { exitToolStripMenuItem.Enabled = false; messageListBox.Items.Clear(); server = new Server(); server.Name = "Server"; server.Progress += new EventHandler <CommunicationProgressEventArgs>(HandleServerProgress); server.Error += new EventHandler <CommunicationErrorEventArgs>(HandleServerError); server.Received += new EventHandler <DataPacketEventArgs>(HandleServerReceived); server.Connect(ipAddressString, port); if (server.Connected) { helloButton.Enabled = true; server.AcceptClients(); toolStrip1.Focus(); } }
private Boolean StartServer(out string errorMessage) { // Start server Boolean ok = true; errorMessage = ""; timeOfLastSpeechOutput = DateTime.MinValue; server.Connect(ipAddress, communicationPort); if (server.Connected) { server.AcceptClients(); if (clientProcessRelativePathList != null) { foreach (string processRelativeFilePath in clientProcessRelativePathList) { string processFilePath = Path.GetDirectoryName(Application.ExecutablePath) + "\\" + processRelativeFilePath; try { Process process = Process.Start(processFilePath); Thread.Sleep(windowMoveMillisecondSleepTime); if (clientProcessList == null) { clientProcessList = new List <Process>(); } clientProcessList.Add(process); } catch (Exception ex) { errorMessage += Path.GetFileName(processFilePath) + " Failed to start:" + ex.Message + "\r\n"; ok = false; } } } } if (!ok) { StopClients(); } return(ok); }