It is weird that sid of socket.io is null, while socket is connected, and can emit message and receive message.
How can I fetch socket id of current connection
It has been a while, any comments?
try getting the id right after you connect your socket object
String id = socket.connect().id();
that worked for me
Please have a look at this, I tried at two place, after connect is called, and on connect event, both will return null.


and I use 0.8.1
compile('io.socket:socket.io-client:0.8.1') {
Hello?
Did it stop working when you updated?, i am currently using 0.8.0. Try calling mSocket.connect().id() when EVENT_CONNECT has been triggered (not just mSocket.id()).

still doesn't work, as you can see, tried it at Socket.EVENT_CONNECT
by call mSocket.connect().id();
Searching "id =" in Socket.java, I can just find this.id only be set to null on call onclose function.
Would you please tell me where it would be set? Thanks!
Add a log saying Log.d(TAG, mSocket.toString()). mSocket data will be a
JSON object, once you print it as a string, then check where the id is
located. Afaik, id is wrapped in another json object within mSocket.
You can then retrieve the ID with basic JSON functions such as
getJSOnobject() followed by getString().
Let me know if this works.
On Fri, Oct 14, 2016 at 11:09 PM, JunfeiW [email protected] wrote:
Searching "id =" in Socket.java, I can just find this.id only be set to
null on call onclose function.—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/socketio/socket.io-client-java/issues/351#issuecomment-253870081,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ALuN-yAKd404cRy_xRXJAN9oGtkCQ0b4ks5qz75tgaJpZM4KMBUW
.
@varunagarwal315 , thanks for reply, mSocket is an instance of Emitter, which hasn't implemented toString(), so when I tried to call mSocket.toString(), the result is "io.socket.client.Socket@21f47178", I didn't find any JSON object. I suppose this 21f47178 is not a id.
I will check it out from my end in a couple of hours, but just curious,
have you been able to manually change the socket ids? I want to make a chat
app and would like each user to have a fixed socket id whenever they
connect, this socket id will be related to their username.
In nodejs, when i change the socket id by socket.id = "customID" upon
connection , it gets changed but I doubt this change is being reflected on
the client side (android). As a result, I cannot send a message to a
specific id. Sending a message to specific id works if I use the default
one assigned which is random.
Has anyone been able to use custom socket id with success? I am using v
0.7.0 as of now.
On Sat, Oct 15, 2016 at 11:00 AM, JunfeiW [email protected] wrote:
@varunagarwal315 https://github.com/varunagarwal315 , thanks for reply,
mSocket is an instance of Emitter, which hasn't implemented toString(), so
when I tried to call mSocket.toString(), the result is
"io.socket.client.Socket@21f47178", I didn't find any JSON object. I
suppose this 21f47178 is not a id.—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/socketio/socket.io-client-java/issues/351#issuecomment-253964269,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ALuN-1C2Fhwpb5F01WpzbSZAX4zcaiTFks5q0GT1gaJpZM4KMBUW
.
Socket mSocket = new Socket()
in the event Socket.EVENT_CONNECT , mSocket.id() is working for me in
version 0.7.0 AND 0.8.0.
I cross checked the socket id by checking it against the socket instance in
my server ( node js)
You are probably called socket.id() on a different instance than the one
which triggered the ON_CONNECT event. I suggest you use initiate a socket
instance using the singleton pattern. This will solve all your problems.
Let me know how it goes!!
On Sat, Oct 15, 2016 at 11:39 AM, Varun Agarwal [email protected]
wrote:
I will check it out from my end in a couple of hours, but just curious,
have you been able to manually change the socket ids? I want to make a chat
app and would like each user to have a fixed socket id whenever they
connect, this socket id will be related to their username.In nodejs, when i change the socket id by
socket.id = "customID"upon
connection , it gets changed but I doubt this change is being reflected on
the client side (android). As a result, I cannot send a message to a
specific id. Sending a message to specific id works if I use the default
one assigned which is random.Has anyone been able to use custom socket id with success? I am using v
0.7.0 as of now.On Sat, Oct 15, 2016 at 11:00 AM, JunfeiW [email protected]
wrote:@varunagarwal315 https://github.com/varunagarwal315 , thanks for
reply, mSocket is an instance of Emitter, which hasn't implemented
toString(), so when I tried to call mSocket.toString(), the result is
"io.socket.client.Socket@21f47178", I didn't find any JSON object. I
suppose this 21f47178 is not a id.—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/socketio/socket.io-client-java/issues/351#issuecomment-253964269,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ALuN-1C2Fhwpb5F01WpzbSZAX4zcaiTFks5q0GT1gaJpZM4KMBUW
.
As far as I know, this socket id is generated by server side, which is used to identify socket clients connected to socket.
I need this to generate auth info for client.
well socket.id() is DEFINITELY working. Make sure you use a singleton
pattern while implement socket in android. Once the socket.id is generated
on server side, it gets send to the client. But If i want to override the
socket.id on server side, how to trigger the client to update it as well.
You may either be
1) not connected to the server properly
2) calling id() on a different instance than the one .connect() was called
on -(avoided by using singleton pattern)
3) Select id() and click cntrl+B on keyboard. This should take you to the
socket superclass where you will get more info on how the id() works
If you use the id for auth info, won't it be better if you could provide
some custom socket id? I need to figure this out badly!
Regards,
On Sat, Oct 15, 2016 at 6:13 PM, JunfeiW [email protected] wrote:
As far as I know, this socket id is generated by server side, which is
used to identify socket clients connected to socket.
I need this to generate auth info for client.—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/socketio/socket.io-client-java/issues/351#issuecomment-253982088,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ALuN-0udyP8nKtuWdeKNe6A8lTvaG22Yks5q0Mp1gaJpZM4KMBUW
.
I did use singleton design for the socket.io, and tried it at CONNECT_EVENT.
I will try to push a project, which can reproduce the problem.
Thanks for reply.
Hi, again
I pushed a project here:
https://github.com/JunfeiW/DemoSocketioID
the implement is here:
https://github.com/JunfeiW/DemoSocketioID/blob/master/app/src/main/java/com/example/socketio/demosocketioid/SocketIOManager.java
I test it on my cell phone, with no luck.
Any help would be appreciated!
The issue is with your basic code. Have made several changes with comments.
Let me know if problem is solved. I would like to be the one who closes the
issue :).
It seems you did not actually initialize the socket instance properly.
Sorry had to change the target SDK, did not have it installed, but it won't
affect the code I have added.
Added a pull request. Accept it.
On Sat, Oct 15, 2016 at 9:13 PM, JunfeiW [email protected] wrote:
Hi, again
I pushed a project here:
https://github.com/JunfeiW/DemoSocketioIDI test it on my cell phone, with no luck.
Any help would be appreciated!—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/socketio/socket.io-client-java/issues/351#issuecomment-253991954,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ALuN-wf2Pj9XRDCFyTQctJgucAa_U53Mks5q0PShgaJpZM4KMBUW
.
Yes, it works, surely, I made something wrong, thanks for all your helps!
Now I know why, it because I use mSocket.off().
access the soket.id from the EVENT_CONNECT
socket = IO.socket("http://192.168.1.129:3000");
socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
@Override
public void call(Object... args) {
String socketID = socket.id();
}
});
socket.connect();
Most helpful comment
Now I know why, it because I use mSocket.off().