Skip to content
This repository has been archived by the owner on Aug 25, 2022. It is now read-only.

Send private message #175

Open
arafsan opened this issue Sep 5, 2018 · 5 comments
Open

Send private message #175

arafsan opened this issue Sep 5, 2018 · 5 comments
Labels

Comments

@arafsan
Copy link

arafsan commented Sep 5, 2018

Hi, how can I use this to send a message to a private socket id ?

@Taluu Taluu added the support label Sep 6, 2018
@peter279k
Copy link
Contributor

peter279k commented Apr 10, 2019

I think you can consider following approach:

  • When it's first to connect the socket server, let server remember authorization token from Autorization header. and the server can bind this token to socket id.
  • Add some credentials (authorization token) in emitted header and client sends this to socket server.
  • When the Socket IO server has received the header, parse header and auth token then send the private message.

@peter279k
Copy link
Contributor

peter279k commented Apr 11, 2019

I've created the PR #187 for this issue.

My approach is as follows:

  • Store the client token and user to prepare for validation on the oncoming connection.
  • I establish three connections and demonstrate these scenarios.

You can take look at more details about the client.php and server.js .

The socket IO server log will be the following output texts:

2019-04-11T06:19:24.135Z - info: SocketIO > listening on port 1337
2019-04-11T06:19:27.208Z - info: auth token this_is_peter_token
2019-04-11T06:19:27.210Z - info: SocketIO > Connected socket M5E21GSH8uWbkk9aAAAA
2019-04-11T06:19:27.210Z - info: X-My-Header websocket rocks
2019-04-11T06:19:27.221Z - info: ElephantIO private_chat_message > {"message":"How are you?","token":"this_is_peter_token"}
2019-04-11T06:19:27.221Z - info: ElephantIO private_chat_message > I am fine, peter
2019-04-11T06:19:27.223Z - info: SocketIO : Received 1 messages
2019-04-11T06:19:27.223Z - info: SocketIO > Disconnected socket M5E21GSH8uWbkk9aAAAA
2019-04-11T06:19:27.225Z - info: auth token this_is_peter_token
2019-04-11T06:19:27.225Z - info: SocketIO > Connected socket Yv8bbaA8-pR1OgKYAAAB
2019-04-11T06:19:27.225Z - info: X-My-Header websocket rocks
2019-04-11T06:19:27.228Z - info: ElephantIO private_chat_message > {"message":"Do you remember me?","token":"this_is_peter_token"}
2019-04-11T06:19:27.228Z - info: ElephantIO private_chat_message > I remember you, peter
2019-04-11T06:19:27.228Z - info: ElephantIO private_chat_message > {"message":"Do you remember me?","token":"this_is_invalid_peter_token"}
2019-04-11T06:19:27.228Z - info: ElephantIO private_chat_message > Token is invalid
2019-04-11T06:19:27.228Z - info: ElephantIO private_chat_message > Sorry. I don't remember you.
2019-04-11T06:19:27.229Z - info: SocketIO : Received 2 messages
2019-04-11T06:19:27.229Z - info: SocketIO > Disconnected socket Yv8bbaA8-pR1OgKYAAAB

@peter279k
Copy link
Contributor

@arafsan, if having any problem about sending messahe to private socket id, please write the comment on this issue :).

@awdynto
Copy link

awdynto commented Oct 24, 2019

Hi, @peter279k I'm just trying to use elephant.io. I have tried #175 (comment) but I still got error like this:

C:\xampp2\htdocs\websocket_tutorial\elephant>node server.js
2019-10-24T07:12:54.198Z - info: SocketIO > listening on port 1337
2019-10-24T07:13:33.332Z - info: auth token this_is_peter_token
2019-10-24T07:13:33.395Z - info: SocketIO > Connected socket 9qTi3VIJekS4OZK5AAAA
2019-10-24T07:13:33.396Z - info: X-My-Header websocket rocks
2019-10-24T07:13:33.865Z - info: SocketIO : Received 0 messages
2019-10-24T07:13:33.867Z - info: SocketIO > Disconnected socket 9qTi3VIJekS4OZK5AAAA
2019-10-24T07:13:33.870Z - info: auth token this_is_peter_token
2019-10-24T07:13:33.872Z - info: SocketIO > Connected socket AjkDLor8gCnb1rZyAAAB
2019-10-24T07:13:33.873Z - info: X-My-Header websocket rocks
2019-10-24T07:13:34.281Z - info: SocketIO : Received 0 messages
2019-10-24T07:13:34.282Z - info: SocketIO > Disconnected socket AjkDLor8gCnb1rZyAAAB

@peter279k
Copy link
Contributor

Hi @awdynto, thanks for your reply.

I'm not sure what kinds of dependencies you use.

Could you provide your Node.js, SocketIO and PHP versions? Thanks.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants