how to join socket room or channel in Socket.IO-client in android

Siamak SiaSoft

I'm new to socket programming and in a project i'm using Socket.IO-client Java to create socket connection between android device and a server . server side developers asked me to connect to the server and then join in a specific room/channel . I'm OK with the first part but how can i join in a room over socket ??

my code is as below :

private void ConnectAndJoin() {
        Log.e("starting:","starting!");

        final Socket socket;
        try {
            socket = IO.socket("http://192.168.1.6:5000");
            socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
                @Override
                public void call(Object... args) {
                    socket.emit("foo", "hi");
                    Log.e("status:","connected- sent");

                    socket.
                }

            }).on("event", new Emitter.Listener() {

                @Override
                public void call(Object... args) {
                    Log.e("status:","event2");

                }

            }).on(Socket.EVENT_DISCONNECT, new Emitter.Listener() {

                @Override
                public void call(Object... args) {
                    Log.e("status:","disconnected");

                }

            });
            socket.connect();
        } catch (URISyntaxException e) {
            Log.e("status:","done with error");
        }

Please give me a help!

Sam

You can't join a room with socket io from the client side . it should happens in the server side.

socket.emit('join-room' , roomName or RoomId)

to tackle this you need to emit a socket with the room you want to join as data , and in the server you listen to this socket and call socket.join() with the name or the id of the room that has been sent.

      socket.on("join-room", new Emitter.Listener() {
      @Override
      public void call(Object... args) {
        room = args[0];
        socket.join(room);
      }
    });

warning : I do not know java so for java devs if you see a syntax mistake you can comment i'll update it

hope it helps!

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

how to join socket room or channel in Socket.IO-client in android

From Dev

node.js and express: how to join a socket.io room/channel based on URL?

From Dev

How to send data to specific client in a specific room with socket io

From Dev

Issue with socket.io join room

From Dev

Socket.io client for Android

From Dev

how to delete a room in socket.io

From Dev

How to decrease socket.io room size

From Dev

how to delete a room in socket.io

From Dev

How to update socket object for all clients in room? (socket.io)

From Dev

Socket.io 1.4.5 How do you send a message to an individual client in a room?

From Dev

socket.io: send message to specific room (client side)

From Dev

Socket.io unable to emit data to client's unique room

From Dev

Using socket.io client library with Android

From Dev

get room of a socket in socket.io

From Dev

socket.io room authorisation

From Dev

How to wait for client response with socket.io?

From Dev

how to detect the same client in socket.io

From Dev

How to use callback on a socket.io CLIENT?

From Dev

How to use cluster on socket.io-client?

From Dev

How to wait for client response with socket.io?

From Dev

Angular-socket-io: how to disconnect the client

From Dev

Socket.io: How to count clients in a room with Socket.io-redis adapter

From Dev

socket.io How to distinguish for which room is the message

From Dev

Nodejs - Socket.io how to detect which room sent the data?

From Dev

How do you stop listening to a socket.io channel?

From Dev

How do you stop listening to a socket.io channel?

From Dev

How do I add a socket.io socket to a room via their socketid?

From Dev

Android developpement, Gottox socket.io-java-client: file not fount Exception /socket.io/1/

From Dev

Android developpement, Gottox socket.io-java-client: file not fount Exception /socket.io/1/

Related Related

  1. 1

    how to join socket room or channel in Socket.IO-client in android

  2. 2

    node.js and express: how to join a socket.io room/channel based on URL?

  3. 3

    How to send data to specific client in a specific room with socket io

  4. 4

    Issue with socket.io join room

  5. 5

    Socket.io client for Android

  6. 6

    how to delete a room in socket.io

  7. 7

    How to decrease socket.io room size

  8. 8

    how to delete a room in socket.io

  9. 9

    How to update socket object for all clients in room? (socket.io)

  10. 10

    Socket.io 1.4.5 How do you send a message to an individual client in a room?

  11. 11

    socket.io: send message to specific room (client side)

  12. 12

    Socket.io unable to emit data to client's unique room

  13. 13

    Using socket.io client library with Android

  14. 14

    get room of a socket in socket.io

  15. 15

    socket.io room authorisation

  16. 16

    How to wait for client response with socket.io?

  17. 17

    how to detect the same client in socket.io

  18. 18

    How to use callback on a socket.io CLIENT?

  19. 19

    How to use cluster on socket.io-client?

  20. 20

    How to wait for client response with socket.io?

  21. 21

    Angular-socket-io: how to disconnect the client

  22. 22

    Socket.io: How to count clients in a room with Socket.io-redis adapter

  23. 23

    socket.io How to distinguish for which room is the message

  24. 24

    Nodejs - Socket.io how to detect which room sent the data?

  25. 25

    How do you stop listening to a socket.io channel?

  26. 26

    How do you stop listening to a socket.io channel?

  27. 27

    How do I add a socket.io socket to a room via their socketid?

  28. 28

    Android developpement, Gottox socket.io-java-client: file not fount Exception /socket.io/1/

  29. 29

    Android developpement, Gottox socket.io-java-client: file not fount Exception /socket.io/1/

HotTag

Archive