static void Main(string[] args) { string ip = null; string port = null; bool riprova = true; AsyncSocketClient mClient = new AsyncSocketClient(); while (riprova) { Console.Write("Inserisci IP:"); ip = Console.ReadLine(); Console.Write("Inserisci Porta:"); port = Console.ReadLine(); if (mClient.SetServerIPAddress(ip) && mClient.SetServerPort(port)) { mClient.ConnectToServer(); riprova = false; } } while (true) { string msg = Console.ReadLine().ToLower(); if (msg == "quit") { break; } mClient.SendMessage(msg); } }
private static void Main(string[] args) { AsyncSocketClient socketClient = new AsyncSocketClient(); socketClient.RaiseMessageReceivedEvent += HandleMessageReceived; socketClient.RaiseServerConnectedEvent += HandleServerConnected; socketClient.RaiseServerDisconnectedEvent += HandleServerDisconnected; Console.WriteLine("Async Socket Client: Started!"); Console.WriteLine("Please type a valid server IP Address and press enter:"); var strServerIpAddress = Console.ReadLine(); Console.WriteLine("Please type a valid port and press enter:"); var strPort = Console.ReadLine(); if (!socketClient.SetServerIpAddress(strServerIpAddress) || !socketClient.SetServerPort(strPort)) { Console.WriteLine("Wrong IP or Port supplied - {0} - {1} - Press a key to exit!", strServerIpAddress, strPort); Console.ReadKey(); return; } socketClient.ConnectToServer(); string strInput = null; do { strInput = Console.ReadLine(); if (strInput != null && strInput.Trim() != "<EXIT>") { socketClient.SendToServer(strInput.Trim()); } else if (strInput != null && strInput.Trim() == "<EXIT>") { socketClient.CloseAndDisconnect(); } } while (strInput != "<EXIT>"); }
private void btnLogin_Click(object sender, RoutedEventArgs e) { string ip = txtIP.Text; string porta = txtPorta.Text; string nick = txtNick.Text; //controllo dei dati if (ip == "" || porta == "" || nick == "" || nick == "inserire nickname") { MessageBox.Show("Fornire tutti i dati"); return; } //creo il client client = new AsyncSocketClient(); if (!client.SetServerIPAddress(ip)) { MessageBox.Show("indirizzo ip non valido"); return; } if (!client.SetServerPort(porta)) { MessageBox.Show("numero di porta non valido"); return; } //connessione al server client.ConnectToServer(); //invio messaggio con credenziali client.SendMessage(txtNick.Text); //apertura finestra di chat Window chat = new Chat(client); chat.Show(); this.Close(); }