static void Main(string[] args) { try { TcpClientCommunication tcpClient = new TcpClientCommunication(); tcpClient.ReadStream = new ReadAnswerTest(); ConnectWindow connectWindow = new ConnectWindow(); var dialogResult = connectWindow.ShowDialog(); if (dialogResult == System.Windows.Forms.DialogResult.OK) { tcpClient.connect(IPAddress.Parse(connectWindow.Adress.Text), int.Parse(connectWindow.PortBox.Text)); if (tcpClient.isConnected) { string message = null; //tcpClient.listening(); SimpleMessage simpleMessage = new SimpleMessage(); simpleMessage.operation = "pobierzid"; tcpClient.send(simpleMessage.buildMessage()); simpleMessage = new SimpleMessage(tcpClient.receiveMessage()); Console.WriteLine($"Połączono z serwerem o adresie {connectWindow.Adress.Text} na porcie {connectWindow.PortBox.Text}"); Console.WriteLine("Możesz wpisywać liczby oddzielone spacją (w liczbach zmiennoprzecinkowych jest używany ',') lub znak/nazwę działania, które chcesz wykonać (jeśli wpiszesz następne działanie, poprzednie zostanie zastąpione)"); Console.WriteLine("Dostępne działania:"); Console.WriteLine("- dodaj (+)"); Console.WriteLine("- odejmij (-)"); Console.WriteLine("- mnozenie (*)"); Console.WriteLine("- dzielenie (/)"); Console.WriteLine("- modulo (%)"); Console.WriteLine("- potega (^)"); Console.WriteLine("- logarytm (log)"); Console.WriteLine("- pierwiastek"); Console.WriteLine("- message "); Console.WriteLine("- exit - rozłącz z serwerem"); Console.WriteLine("- send - wyślij działanie"); while (simpleMessage.operation != "exit") { do { Console.Write("ID: " + simpleMessage.id + "> "); message = Console.ReadLine(); } while (simpleMessage.add(message)); tcpClient.send(simpleMessage.buildMessage()); message = tcpClient.receiveMessage(); simpleMessage = new SimpleMessage(message); Console.WriteLine("Status odpowiedzi: " + SimpleMessage.statusName[int.Parse(simpleMessage.status)]); Console.WriteLine(simpleMessage.dateTime.ToString() + $" - Wynik) {simpleMessage.numbersToString()}"); } tcpClient.Close(); } else { Console.WriteLine("Nie udało się połączyć z serwerem"); } } }catch (Exception e) { Console.WriteLine(e.ToString()); } Console.WriteLine("END"); Console.Read(); }
/** Questo metodo intercetta l'input del mouse sulla cella contenente l'indirizzo ip del server **/ void DataGridServer_GotMouseCapture(object sender, MouseEventArgs e) { int item = DataGridServer.SelectedIndex; if (item < MainWindow.listIp.Count) // Ho cliccato su una riga valorizzata { IpAddress i = (IpAddress)DataGridServer.SelectedItem; if (i != null) { ConnectWindow c = new ConnectWindow(); c.ipAddress.Text = i.ipAddress; MainWindow.serverIP = System.Net.IPAddress.Parse(i.ipAddress); c.Show(); this.Close(); } } }
/// <summary> /// Launching client window /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void App_OnStartup(object sender, StartupEventArgs e) { var connectForm = new ConnectWindow(); if (connectForm.ShowDialog() != true) { return; } var chatClient = new ChatClient(connectForm.PortNumber, connectForm.IpAddress, connectForm.UserName); if (!chatClient.IsConnected) { Current.Shutdown(); return; } var clientForm = new ClientWindow(chatClient); clientForm.Show(); }
private void searchAndConnectServer() { ConnectWindow connectWindow = new ConnectWindow(); connectWindow.ShowDialog(); if (connectWindow.FoundServers > 0) { string serverUri = (string)connectWindow.serverComboBox.SelectedValue; try { Uri baseAddress = new Uri(serverUri); EndpointAddress address = new EndpointAddress(baseAddress); NetTcpBinding binding = new NetTcpBinding(); binding.Security.Mode = SecurityMode.None; factory = new ChannelFactory <IServerService>(binding, address); serverService = factory.CreateChannel(); ((IContextChannel)serverService).OperationTimeout = TimeSpan.MaxValue; Dispatcher.BeginInvoke(new Action(() => { this.serverConnectLabel.Content = "Połączenie z serwerem: Połączono"; })); } catch (Exception ex) { MessageBox.Show(ex.Message); Application.Current.Shutdown(); } } else { Application.Current.Shutdown(); } }
private void connect(object sender, RoutedEventArgs e) { ConnectWindow c = new ConnectWindow(); c.Show(); }
private async void _listener_OnKeyPressed(object sender, INPUT e) { bool error = false; string message = ""; try { if (Keyboard.Modifiers == ModifierKeys.Control) { Key k = KeyInterop.KeyFromVirtualKey(e.ki.wVk); int virtualKey = KeyInterop.VirtualKeyFromKey(k); if (k == Key.N) { // Invio della clipboard del client ClientManager.NotifyClipboardAsynch(); } else if (k == Key.M) { // Richiesta della clipboard al server ClipboardTrasfer.SendUpdateRequest(); } else if (virtualKey >= (int)VirtualKeyCode.VK_1 && virtualKey <= (int)VirtualKeyCode.VK_9) // Switch { virtualKey -= (int)VirtualKeyCode.VK_0; if (virtualKey <= listIp.Count) { serverIP = IPAddress.Parse(listIp[virtualKey - 1].ipAddress); Connection.disconnectFromServer(); ConnectWindow c = new ConnectWindow(); c.Show(); } } else if (virtualKey == (int)VirtualKeyCode.VK_0) // Disconnect { MessageDialogResult result = await this.ShowMessageAsync("Exit", "Are you sure you want to disconnect?", MessageDialogStyle.AffirmativeAndNegative, WPFProperties.metroDialogSettings); if (result == MessageDialogResult.Affirmative) { if (disconnectButton.IsEnabled) { Connection.disconnectFromServer(); } } } else { ClientManager.NotifyInputAsynch(e); } } else { ClientManager.NotifyInputAsynch(e); } } catch (Exception ex) { error = true; message = ex.Message; } if (error) { MessageDialogResult result = await this.ShowMessageAsync("Error: " + message, "You are now disconnected from server", MessageDialogStyle.Affirmative, WPFProperties.metroDialogSettings); } }