Ejemplo n.º 1
0
  public Model(Socket s) {
    listeners = new ArrayList<>();
    String url = "https://cryptic-brushlands-8704.herokuapp.com";
    // String url = "http://192.168.119.233:5000";
    try {
      s = IO.socket(url);
    } catch (URISyntaxException e) {
      Log.e("Connection Error", "Socket was unable to connect");
      e.printStackTrace();
    }
    // Adds the callback funtions for socket events
    s.on("topic", topic);
    s.on("id", id);

    s.connect();

    this.socket = s;

    topics = new ArrayList<>();
    poll = new HashMap<>();
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Button connectButton = (Button) findViewById(R.id.connectButton);
    textView1 = (TextView) findViewById(R.id.textView1);

    try {
      WifiManager manager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
      WifiInfo info = manager.getConnectionInfo();
      String address = info.getMacAddress();

      String address1 = address.replaceAll(":", "");
      String address2 = address1.toUpperCase();
      finalAddress = "AABBCCDDEEFF" + address2;

      // mSocket = IO.socket("http://chat.socket.io");
      String url = "http://192.168.2.133:3000/?clientId=" + finalAddress;
      mSocket = IO.socket(url);
      // mSocket = IO.socket("http://192.168.2.133:3000/?clientId=AABBCCDDEEFF005C889036BB");

    } catch (URISyntaxException e) {
    }

    connectButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View arg0) {
            WifiManager manager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
            WifiInfo info = manager.getConnectionInfo();
            String address = info.getMacAddress();

            textView1.setText("mac address--------" + finalAddress);
          }
        });

    mSocket.on("tag message", onNewMessage);
    mSocket.connect();
  }
Ejemplo n.º 3
0
 {
   try {
     socket = IO.socket("http://159.203.4.161:3000");
   } catch (URISyntaxException e) {
   }
 }