Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send message to specific connected user or to all connected users #101

Open
colomarco opened this issue Jul 10, 2017 · 5 comments
Open

Send message to specific connected user or to all connected users #101

colomarco opened this issue Jul 10, 2017 · 5 comments

Comments

@colomarco
Copy link

I know that is not an issue and I'm sorry but I don't know where to write.
All works great, but I don't understand how is possible to send a specific message to a desired user or to all connected users. Is it possible to have few examples about that??
Thank you so much!

@oguls
Copy link

oguls commented Jul 10, 2017

Hi,

In echoserver example file "testwebsock.php"

  protected function process ($from, $message) { // changed $user to $from, just to avoid confusion
	foreach ($this->users as $user){ // sending to all connected users
		if($from !== $user){ // avoid to send msg to sender
			$this->send($user, $message);
		}
	}
  }

@colomarco
Copy link
Author

@oguls Thank you very much!!!

@renznamoc21
Copy link

How can i send to specific user connected to socket?

@oguls
Copy link

oguls commented Aug 15, 2018

Your all connected users are in this object/array $user, try to print_all to check how this array structure looks like.

To send to specific user you need to know the id of user like $user[id] then
$this->send($user[id], $message)

@renznamoc21
Copy link

@oguls thank you very much.
It might be out of discussion to ask, but is it possible to call send function inside codeigniter controller ?
Javascript:
socket.send('message');
Php :
any equivalent of js sample in php ?

Thank you very much!!!

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

No branches or pull requests

3 participants