private static void Disconnect() { stream?.Close(); client?.Close(); Environment.Exit(0); }
static void Disconnect() { reader?.Close(); writer?.Close(); client?.Close(); }
public void Close() { stream?.Close(); client?.Close(); }
/// <summary> /// Closes the stream and the client connection once the window gets closed / exited. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e) { stream?.Close(); client?.Close(); }
private void Form1_FormClosing(object sender, FormClosingEventArgs e) { stream?.Close(); tcp?.Close(); }
private void getMessage() { try { while (true) { serverStream = clientSocket.GetStream(); byte[] inStream = new byte[10025]; serverStream.Read(inStream, 0, inStream.Length); List <string> parts = null; if (!SocketConnected(clientSocket)) { MessageBox.Show("You've been Disconnected"); ctThread.Abort(); clientSocket.Close(); btnConnect.Enabled = true; } parts = (List <string>)ByteArrayToObject(inStream); switch (parts[0]) { case "userList": getUsers(parts); break; case "gChat": readData = "" + parts[1]; msg(); break; case "pChat": managePrivateChat(parts); break; } if (readData[0].Equals('\0')) { readData = "Reconnect Again"; msg(); this.Invoke((MethodInvoker) delegate // To Write the Received data { btnConnect.Enabled = true; }); ctThread.Abort(); clientSocket.Close(); break; } chat.Clear(); } } catch (Exception e) { ctThread.Abort(); clientSocket.Close(); btnConnect.Enabled = true; Console.WriteLine(e); } }
public void RunClient() { TcpClient client = null; //instantiate TcpClient for sending data to server try { //Create TcpClient for sending data to server client = new TcpClient(); client.Connect("127.0.0.1", 50000); //Get NetworkStream associated with TctClient output = client.GetStream(); //Create objects for writing and reading across stream writer = new BinaryWriter(output); reader = new BinaryReader(output); //Loop until server signals termination do { //Processing phase try { //Read message from server message = reader.ReadString(); if (message.Equals("SERVER >>> Successful Authentication")) { HideLoginPanels(); ShowOperationsPanel(); } //Check user permissions if (message.Equals("SERVER >>> Cannot make encryption from guest account.")) { MessageBox.Show("Cannot make encryptions from guest account.", "Unauthorized Operation"); } //Check user card if (message.Equals("SERVER >>> Invalid card number")) { MessageBox.Show("The card number you have entered is incorrect. Check if this is your card number.", "Invalid Card Number"); } //Chech number of times user have encrypted his card if (message.Equals("SERVER >>> Cannot make more than 12 encryptions")) { MessageBox.Show("You cannot make more than 12 ecryptions per card.", "Invalid Operation"); } //Check permissions for decrypt if (message.Equals("SERVER >>> Cannot decrypt this card.")) { MessageBox.Show("You have no permissions to decrypt this card. Check if this is your card encryption.", "Invalid Operation"); } //Get encryption/Decryption if (Regex.IsMatch(message, @"^[0-9]+$")) { DisplayOutput(message); } } catch (Exception) { System.Environment.Exit(System.Environment.ExitCode); } } while (message != "SERVER>>> TERMINATE"); } catch (Exception exception) { MessageBox.Show(exception.ToString(), "Connection Error", MessageBoxButton.OK, MessageBoxImage.Error); } finally { //Close connection writer?.Close(); reader?.Close(); output?.Close(); client?.Close(); System.Environment.Exit(System.Environment.ExitCode); } }
public void unConnect() { tc.Close(); }