ghedipunk / PHP-Websockets

A Websockets server written in PHP.
BSD 3-Clause "New" or "Revised" License
913 stars 375 forks source link

How to send Custom client Id in server.php file? #50

Closed vksdgreat closed 8 years ago

vksdgreat commented 8 years ago

Hello, I am planning to connect this websocket with my database, so I am putting my database code in server.php file. but i did not want to send and autogenerated clientId instead i want to send clientId registered in database so i want to know how to send a client id from index.html to server.php?

lgaitan commented 8 years ago

Hello, If i got it right, you want the client to identifies himself to server. Then you'll have to send that information via javascript

    var clientid = 'xx';
    socket.send(clientid);

I would recommend sending data in json format, it will be much easier to handle in server side. Then you should try something like this

    var clientid = 'xx';
    var json = '{"task":"auth","clientid":clientid}';
    socket.send(json);

If this information is really important, and you need it as soon the client is connected, put this code inside socket.onopen event.

ghedipunk commented 8 years ago

You'll need to extend the WebSocketClient class to add custom fields to a connection.

vksdgreat commented 8 years ago

Thank you LGaitan i will try this