public static void Main(string[] args) { var server = new SocketServer(IPAddress.Parse(Ip), Port); server.Start(); var input = string.Empty; while (input.ToLower() != "q") { Console.WriteLine("Enter 'Q' or 'q' to exit."); input = Console.ReadLine().ToLower(); } server.Stop(); server.Dispose(); }
private void tspbtnStart_Click(object sender, EventArgs e) { // 按扭 this.tsptxbServerIp.ReadOnly = true; this.tsptxbServerPort.ReadOnly = true; this.tspbtnStart.Enabled = false; try { // 建立伺服端 Server = new SocketServer(this.tsptxbServerIp.Text, this.tsptxbServerPort.Text, this); // 運行伺服端 Task.Factory.StartNew(() => Server.Start(), TaskCreationOptions.LongRunning); } catch (Exception ex) { ServerError.Error("啟動伺服器時發生錯誤!\n\rMessage: {0},\r\n StackTrace: {1}\r\n", ex.Message, ex.StackTrace); } }