Jump to content

Identify client PHP socket


AntonZelenin

Recommended Posts

Is there a way to assign some unique value to a php socket? By default they get id's starting from 1, then 2, 3 and so on. Could I assign the value I want to a new socket connection?
If no, how to identify specific user socket to send him a message? Just tell every connected user his temporary id and save it to database?

Link to comment
Share on other sites

Is there a way to assign some unique value to a php socket? By default they get id's starting from 1, then 2, 3 and so on. Could I assign the value I want to a new socket connection?

What kind of "value" are you thinking about?

 

If no, how to identify specific user socket to send him a message? Just tell every connected user his temporary id and save it to database?

:psychic:

 

Going to need context for that.

Link to comment
Share on other sites

What kind of "value" are you thinking about?

 

:psychic:

 

Going to need context for that.

Randomly generated value.. or maybe user id from database.

 

 

About context. For example, several users connected to my server. And now I see this:

print_r($this->clients);

Array

(

   [0] => Resource id #5

   [1] => Resource id #6

   [2] => Resource id #7

)

 

So I can't figure out who is who. That's why I've got a question if I could specify id for a new socket)

 

I could give you source code if needed:)

Edited by AntonZelenin
Link to comment
Share on other sites

This piece of code accepts new sockets

$changed = $this->clients;

socket_select($changed, $null, $null, 0, 10);

if (in_array($this->socket, $changed)) {
     $socket_new = socket_accept($this->socket);
     $this->clients[] = $socket_new;

     $header = socket_read($socket_new, 1024);
     $this->perform_handshaking($header, $socket_new, $this->host, $this->port);

    $found_socket = array_search($this->socket, $changed);
    unset($changed[$found_socket]);
}
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.