private void Listen(int port) { int count = 1; // Listen for input coming from any IP address on specified port listener = new TcpListener(IPAddress.Any, port); listener.Start(); DisplayTextBox.AppendText("Server Running" + Environment.NewLine); try { while (true) { // Create an event handler for dealing with incoming connections client = listener.AcceptTcpClient(); lock (hum) list_clients.Add(count, client); thread = new Thread(receiver); thread.Start(count); count++; } } catch (Exception) { } //For some reason it kind of crashes but it continues to run still receiving users, broadcasting messages, etc...... }
} // End event private void sortButton_Click(object sender, EventArgs e) { DisplayTextBox.AppendText("Sorted Array:\n"); sortedArr = bubbleSort(array); displayArray(sortedArr); sortButton.Enabled = false; inputTextBox.Focus(); inputTextBox.SelectAll(); } // End event
} // End event private void genRandArrButton_Click(object sender, EventArgs e) { clearText(); arrLen = Int32.Parse(inputTextBox.Text); array = randArray(arrLen); DisplayTextBox.AppendText("Unsorted Array:\n"); displayArray(array); sortButton.Enabled = true; } // End event
private void DgtBtn_Clck(object sender, EventArgs e) { Button btn = (Button)sender; if (DisplayTextBox.Text == "0") { DisplayTextBox.Clear(); } DisplayTextBox.Text += btn.Text; }
} // End function private void displayArray(int[] array) { for (int i = 0; i < array.Length; i++) { DisplayTextBox.AppendText(array[i] + " "); if ((i + 1) % 10 == 0) { // Only allows 10 numbers per line DisplayTextBox.AppendText("\n"); } } } // End function
private void Connect(string ipaddress, int port) { try { // Try to make a socket connection socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); socket.BeginConnect(ipaddress, port, ConnectHandler, socket); } catch (Exception ex) { DisplayTextBox.AppendText("Socket Connection error:\n" + ex.ToString()); } }
private void ConnectHandler(IAsyncResult info) { //Which socket is this using? Socket s = (Socket)info.AsyncState; //Complete The Connection try { s.EndConnect(info); DisplayTextBox.AppendText("Connected to a server" + Environment.NewLine); } catch (Exception ex) { DisplayTextBox.AppendText("Could not Connect to the server as it is refusing any connection" + Environment.NewLine); } // Set up an event handler for receiving messages on socket s Receive(s); }
private void ReceiveHandler(IAsyncResult info) { try { // Which socket is this using? Socket s = (Socket)info.AsyncState; // Read Message int numBytesReceived = s.EndReceive(info); string message = Encoding.ASCII.GetString(buffer, 0, numBytesReceived); //Update Display DisplayTextBox.AppendText(message); //Reset The event Handler for new incoming messages on socket s Receive(s); } catch (Exception ex) { } }
private void EuroButton_Click(object sender, EventArgs e) { if (DisplayTextBox.Text == "0") { DisplayTextBox.Clear(); if (!DisplayTextBox.Text.Contains("€")) { containsEuro = true; DisplayTextBox.Text = "€" + DisplayTextBox.Text; } } else { if (!DisplayTextBox.Text.Contains("€")) { containsEuro = true; DisplayTextBox.Text = "€" + DisplayTextBox.Text; } } }
public void TakeMessage(string message, string spacecraftname) { DisplayTextBox.Text += spacecraftname + ":" + message + "\n"; DisplayTextBox.ScrollToEnd(); }
/// <summary> /// Sets a text in the textbox, without parsing it. /// </summary> /// <param name="text">The text to be set in the textbox.</param> /// <remarks>Sets focus to the textbox.</remarks> internal void SetText(string text) { DisplayTextBox.Focus(); DisplayTextBox.Text = text; }
} // End function private void clearText() { DisplayTextBox.Clear(); // Clears everything in the text box } // End function