Skip to content

Not sending message via php #24

@JacoSJKruger

Description

@JacoSJKruger

Hi there,

I've changed the php text to "ws://localhost:8282" as having it as 0.0.0.0 was giving a 10049 error (where as localhost doesn't give any error).

Still it seems to not be working correctly. If I connect via javascript it seems to be working fine, but when I send a message using php I don't get anything.

PHP (not working)
`public function test_webs(){
$socket_client = new WebSocket\Client("ws://0.0.0.0:8282");

  $socket_client->send(json_encode(array('user_id' => 1, 'message' => null)));
   $socket_client->send(json_encode(array('user_id' => 1, 'message' => 'Super cool message to myself!')));
}`

javascript (working fine)
`var conn = new WebSocket('ws://localhost:8282');
var client = {
user_id: 5,
recipient_id: null,
type: 'socket',
token: null,
message: null
};

conn.onopen = function (e) {
    conn.send(JSON.stringify(client));
    console.log("Socket open");
};

conn.onmessage = function (e) {
    var data = JSON.parse(e.data);
    if (data.message) {

        console.log("Incomming User "+data.user_id+": ");
        console.log(data.message);
    }
    if (data.type === 'token') {
        // $('#token').html('JWT Token : ' + data.token);
        console.log('JWT Token : ' + data.token);
    }
};`

Assistance will be appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions