public void sendMessage(View view) {
    EditText et = (EditText) findViewById(R.id.editText1);
    final String msg = et.getText().toString();
    et.setText("");
    new Thread(
            new Runnable() {
              public void run() {
                Socket sock = null;
                try {
                  sock = new Socket(ipAddr, sendPort);
                  Log.v(
                      TAG,
                      "send sock: "
                          + sock.getInetAddress().getHostAddress()
                          + sock.isConnected()
                          + Integer.toString(sock.getPort()));
                } catch (UnknownHostException e) {
                  Log.v(ERRORTAG, "" + e.getMessage());
                  e.printStackTrace();
                } catch (IOException e) {
                  Log.v(ERRORTAG, "" + e.getMessage());
                  e.printStackTrace();
                }

                try {
                  PrintWriter out = new PrintWriter(sock.getOutputStream(), true);
                  out.println(msg);
                  updateTextView("<font color=\"#800000\"> <b>Sent: </b></font>" + msg);
                } catch (IOException e) {
                  Log.v(ERRORTAG, "" + e.getMessage());
                  e.printStackTrace();
                }
              }
            })
        .start();
  }
  public void tryLogin() {
    mName = mEtAccount.getText().toString();
    mPassword = mEtPassword.getText().toString();

    if (mName.equals("") || mPassword.length() < 5) { // Please Specify Your Name and Sex"
      Toast.makeText(
              MainActivity.this,
              "Please Specify Your Name and Password correctly",
              Toast.LENGTH_LONG)
          .show();
    } else {
      mUserInfo = new UserInfo(mName, 0, 0, 0, 0, 0, 0);

      /*  if mNetcon is connected already, close it first  */
      /*  here we use try because mNetCon might not have been instantiated yet  */
      /*			try {
      				NetConnect.getnetConnect().closeNetConnect();
      			} catch (Exception e) {}
      			try {
      				InitData.closeInitData();
      				FriendListInfo.closeFriendListInfo();
      				ChatServiceData.closeChatServiceData();
      			} catch (Exception e) {}
      */
      CloseAll.closeAll();
      /*  to establish a new connect  */

      NetworkService.getInstance().onInit(this);
      NetworkService.getInstance().setupConnection();
      if (NetworkService.getInstance().getIsConnected()) {
        String usrInfo =
            mUserInfo.toString()
                + GlobalStrings.signinDivider
                + mPassword
                + GlobalStrings.signinDivider;
        NetworkService.getInstance().sendUpload(GlobalMsgTypes.msgHandShake, usrInfo);
      } else {
        NetworkService.getInstance().closeConnection();
        Toast.makeText(this, "failed to connect to Server", Toast.LENGTH_LONG).show();
        return;
      }

      InitData initData = InitData.getInitData();
      initData.start();
      try {
        initData.join();
      } catch (Exception e) {
      }
      mUserInfo = initData.getUserInfo();

      Log.d(
          "connectedApp isonline : ",
          ""
              + mUserInfo.getIsOnline()
              + "+++++++++++++"
              + "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");

      if (mUserInfo.getId() < 0) {
        Toast.makeText(this, "invalid username or password", Toast.LENGTH_SHORT).show();
        return;
      }

      Log.d(
          "connectedApp isonline : ",
          ""
              + mUserInfo.getIsOnline()
              + "+++++++++++++"
              + "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");

      ConnectedApp connected_app0 = ConnectedApp.getInstance();
      //		    connected_app0.setConnect(mNetCon);
      connected_app0.setUserInfo(mUserInfo);
      connected_app0.clearListActivity();
      connected_app0.instantiateListActivity();

      Intent intent0 = new Intent(MainActivity.this, MainBodyActivity.class);
      //			intent0.putExtra("username", mUserInfo.getName());
      //			intent0.putExtra("usersex", mUserInfo.getSex());
      startActivity(intent0);

      finish();
    }
  }