Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class LogIn extends Activity implements View.OnClickListener{
- private Socket socket;
- private DataOutputStream out;
- private DataInputStream in;
- private String username,password,s;
- EditText eT_username,eT_password;
- Button b_login,b_signup,b_connect;
- TextView t;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_log_in);
- eT_username = (EditText)findViewById(R.id.eT_username);
- eT_password = (EditText)findViewById(R.id.eT_password);
- b_login = (Button)findViewById(R.id.b_login);
- b_signup = (Button)findViewById(R.id.b_signup);
- b_connect = (Button)findViewById(R.id.b_connect);
- t = (TextView)findViewById(R.id.tV);
- b_login.setOnClickListener(this);
- }
- @Override
- public void onClick(View v) {
- String toast_msg;
- try {
- out = new DataOutputStream(socket.getOutputStream());
- in = new DataInputStream(socket.getInputStream());
- out.writeUTF("1");
- username = eT_username.getText().toString();
- password = eT_password.getText().toString();
- out.writeUTF(username);
- // out.flush();
- out.writeUTF(password);
- // out.flush();
- t.setText("hi");
- s = in.readUTF();
- if (s.equals("ok")) {
- toast_msg = "Login is successfull";
- t.setText(toast_msg);
- } else {
- toast_msg = "username or password is incorrect";
- t.setText(toast_msg);
- }
- } catch (IOException e) {
- t.setText(e.toString());
- }
- }
- public void connect(View v)
- {
- new Thread(new Runnable() {
- @Override
- public void run() {
- try
- {
- socket = new Socket("192.168.0.101",5000);
- }
- catch(Exception e)
- {
- TextView t = (TextView)findViewById(R.id.textView);
- t.setText(e.toString());
- // Toast.makeText(LogIn.this,"Make sure that you are connected to Internet",Toast.LENGTH_LONG).show();
- }
- }
- }).start();
- }
- public void openSignUp(View v)
- {
- if (v.getId()== R.id.b_signup)
- {
- Intent i = new Intent(LogIn.this,SignUp.class);
- startActivity(i);
- }
- new SignUp(socket);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement