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:)

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.