public ControlForm(string IPAddress, TargetController target) { // // Required for Windows Form Designer support // InitializeComponent(); myTarget = target; myIPAddress = IPAddress; this.IPLabel.Text = "Tagret IP Address: " + myIPAddress; }
/// <summary> /// Listen for Ghost connections /// </summary> public void Start() { try { // Set the TcpListener on port 80. Int32 port = 80; // Use "0" to let the IP Stack figure out the IP Address IPAddress localAddr = IPAddress.Parse("0"); myServer = new TcpListener(localAddr, port); // Start listening for client requests. myServer.Start(); listening = true; // Enter the listening loop. while (listening) { // See if a connection request is pending if (!myServer.Pending()) { // Wait 50 milliseconds and then try again Thread.Sleep(50); if (!listening) { break; } continue; } // Perform a blocking call to accept requests. TcpClient client = myServer.AcceptTcpClient(); // Spawn a new TargetController for each new connection myTarget = new TargetController(mainFormPtr, client); myThread = new Thread(new ThreadStart(myTarget.Start)); // Start the TARGET thread. myThread.Start(); } } catch (SocketException) { string message = "Could not get a port 80 socket.\n" + "Make sure the port is not in use.\n" + "(IIS uses port 80 on most servers)"; mainFormPtr.Alert(null, message); } catch (ThreadAbortException) { // Application is shutting down } }
public void AddTarget(TargetController target, string targetAddress, string targetInfo) { // Save the TargetController class myTarget = target; // Add the target to the list view string[] columns = new string[3]; // Add Item to the ListView control. columns[0] = targetAddress; columns[1] = targetInfo; columns[2] = "0"; ListViewItem item = new ListViewItem(columns); this.targetListView.Items.Add(item); this.targetListView.EnsureVisible(this.targetListView.Items.Count - 1); }