/// <summary> /// /// </summary> /// <param name="type">ulp operation type: login/register</param> /// <param name="data">additional data to be pass</param> public ULP(ulpOperation type, string data = "") { this.version = 0x01; this.operationStatus = ulpOperStatus.NONE; this.operationType = type; this.protocolStatus = IStatus.OK; this.data = 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); }