public TabTextItem AddShellTab(RemoteClient client, string initMsg, string ip) { var tab = new TabTextItem { title = ip, client = client, text = initMsg }; this.AddCachedTab(tab); // 超过一定数量就不自动弹出来了 if (this.cachedTabTextList.Count <= 1) { this.ShowShellTab(ip); } return(tab); }
public void RunServer() { while (true) { // 获取一个连接,同步方法,在此处中断 var client = _listener.AcceptTcpClient(); // 如果勾选,一个IP只保留一个,则自动判断 var sameIpExists = false; if (_mainForm.ckbKeepOne.Checked) { lock (ClientList) { foreach (var item in ClientList) { var remoteIp = client.Client.RemoteEndPoint.ToString().Split(':')[0]; var itemIp = item._remoteEndPoint.Split(':')[0]; if (itemIp.Equals(remoteIp)) { WriteLog($"This IP has exists! Skip this connection. {client.Client.RemoteEndPoint}"); sameIpExists = true; break; } } } } if (!sameIpExists) { var remoteClient = new RemoteClient(client, _mainForm, this); ClientList.Add(remoteClient); remoteClient.BeginRead(); } else { // 断开连接 try { client?.Close(); } catch (Exception e) { } } } }
public ShellTab(RemoteClient client) { InitializeComponent(); _client = client; RtbShell = new RichTextBox { Dock = DockStyle.Fill, BackColor = Color.Black, ForeColor = Color.LimeGreen, }; try { RtbShell.Font = new Font("Consolas", 10.5f); } catch { } RtbShell.SelectionFont = new Font(RtbShell.Font.FontFamily, 10.5f); this.Controls.Add(RtbShell); RtbShell.KeyUp += new System.Windows.Forms.KeyEventHandler(this.RtbShell_KeyUp); //RtbShell.KeyUp += new System.Windows.Forms.KeyEventHandler(this.RtbShell_KeyUp); RtbShell.TextChanged += new System.EventHandler(this.RtbShell_TextChanged); }