static string Logowanie() { //////////////////////////////////////// Console.WriteLine("Zaloguj się podając login i hasło:"); var login = Console.ReadLine(); var haslo = Console.ReadLine(); Name = login; var data = new StringBuilder(login); data.Append(" "); data.Append(haslo); ///////////////////////////////////////// var IP = IPAddress.Parse("127.0.0.1"); TcpClient tcpClient = new TcpClient(new IPEndPoint(IP, 0)); tcpClient.Connect(IPAddress.Parse("127.0.0.1"), 8086); SslStream sslClient = new SslStream(tcpClient.GetStream(), false, new RemoteCertificateValidationCallback(ValidateServerCertificate), null); try { sslClient.AuthenticateAsClient("TIPserver"); //Console.WriteLine("Uwierzytelniono"); } catch (Exception ex) { Console.WriteLine(ex.Message); } ULP cmd = new ULP(ulpOperation.LOGIN, data.ToString()); //Console.WriteLine("Wysłano: " + cmd.ToString()); string msg = cmd.ToString(); sslClient.Write(ASCIIEncoding.ASCII.GetBytes(msg), 0, msg.Length); byte[] tab = new byte[150]; int i = sslClient.Read(tab, 0, 150); ULP result = new ULP(Encoding.ASCII.GetString(tab)); Console.WriteLine(result.OperationStatus.ToString()); //Console.WriteLine(Encoding.ASCII.GetString(tab),0,i); //Console.WriteLine("Odebrano: " + result.ToString()); //Console.WriteLine(""); sslClient.Close(); tcpClient.Close(); return(result.data); }
/*<summary> * sends login and password for login/register and return response from server * </summary> */ private ULP send_login_data(ulpOperation operation, Int32 port) { machineName = txt_server_add.Text; TcpClient client = new TcpClient(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 0)); client.Connect(server_addres, 8086); SslStream sslStream = new SslStream( client.GetStream(), false, new RemoteCertificateValidationCallback(ValidateServerCertificate), null ); try { sslStream.AuthenticateAsClient(serverName); } catch (AuthenticationException e) { Console.WriteLine("Exception: {0}", e.Message); if (e.InnerException != null) { Console.WriteLine("Inner exception: {0}", e.InnerException.Message); } Console.WriteLine("Authentication failed - closing the connection."); client.Close(); } ULP sendFrame = new ULP(operation, txt_login.Text + ' ' + txt_pass.Text); byte[] sendBytes = Encoding.ASCII.GetBytes(sendFrame.ToString()); sslStream.Write(sendBytes); sslStream.Flush(); //client.GetStream().WriteAsync(sendBytes, 0, sendBytes.Length); byte[] buffer = new byte[1500]; sslStream.Read(buffer, 0, buffer.Length); // Close the client connection. client.Close(); ULP frame = new ULP(Encoding.ASCII.GetString(buffer, 0, buffer.Length)); return(frame); }