protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); // Get our button from the layout resource, // and attach an event to it EditText usuario = FindViewById <EditText>(Resource.Id.usuarioInput); EditText pass = FindViewById <EditText>(Resource.Id.passInput); TextView error = FindViewById <TextView>(Resource.Id.textError); Button button = FindViewById <Button>(Resource.Id.botonLog); button.Click += delegate { string txt = ""; if (hayInternet()) { model.Experimento exp = ServerConnection.logeaExperimento(usuario.Text, pass.Text); //TODO dependiendo del tipo e id Intent intent = null; switch (exp.Tipo) { case -1: txt = "Error al conectar"; break; case 0: txt = "Credenciales incorrectos"; break; case 1: intent = new Intent(this, typeof(BeautyContestActivity)); intent.SetFlags(ActivityFlags.NewTask); intent.PutExtra("USUARIO", usuario.Text); intent.PutExtra("RONDAS", exp.Rondas); intent.PutExtra("RONDA", 1); StartActivity(intent); break; case 2: intent = new Intent(this, typeof(FondosActivity)); intent.SetFlags(ActivityFlags.NewTask); intent.PutExtra("USUARIO", usuario.Text); intent.PutExtra("RONDAS", exp.Rondas); intent.PutExtra("RONDA", 1); intent.PutExtra("IDEXP", exp.Id); StartActivity(intent); break; } } else { txt = "No hay conexion a Internet"; } error.Text = txt; }; }
public static model.Experimento logeaExperimento(string usuario, string clave) { model.Experimento exp = new model.Experimento(); //Creacion del socket IPAddress ip = IPAddress.Parse(ipServer); IPEndPoint endPoint = new IPEndPoint(ip, port); Socket clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); try { //Conectamos al servidor clientSocket.Connect(endPoint); //Trabajamos con el socket clientSocket.Send(BitConverter.GetBytes(1)); //Codigo de la operacion //Enviamos clientSocket.Send(BitConverter.GetBytes(usuario.Length)); //Longitud del string clientSocket.Send(System.Text.Encoding.ASCII.GetBytes(usuario)); clientSocket.Send(BitConverter.GetBytes(clave.Length)); //Longitud del string clientSocket.Send(System.Text.Encoding.ASCII.GetBytes(clave)); //Recibimos byte[] buffer = new byte[4]; clientSocket.Receive(buffer); exp.Id = bytesToInt(buffer); clientSocket.Receive(buffer); exp.Tipo = bytesToInt(buffer); clientSocket.Receive(buffer); exp.Rondas = bytesToInt(buffer); //Cerramos la conexion clientSocket.Shutdown(SocketShutdown.Both); clientSocket.Close(); }catch (Exception) { exp = new model.Experimento(); exp.Id = -1; exp.Tipo = -1; } return(exp); }