Php 如何在AWS上的Codeigniter中使用WebSocket实现服务器消息?A.

Php 如何在AWS上的Codeigniter中使用WebSocket实现服务器消息?A.,php,amazon-web-services,codeigniter,websocket,amazon-lightsail,Php,Amazon Web Services,Codeigniter,Websocket,Amazon Lightsail,因此,我刚刚在我的Codeigniter应用程序中使用了WebSocket和这个库。它在localhost上运行得很好,但当我将所有这些代码推送到AWS实例时,我无法获得任何消息 我已经完成了自述文件中的所有步骤,将库添加到我的服务器中,我甚至可以通过在两个“客户端”之间发送消息来进行测试。但是,我需要从我的控制器发送消息,并且需要在我的视图中显示这些消息 我的控制器类: <?php defined('BASEPATH') OR exit('No direct script access

因此,我刚刚在我的Codeigniter应用程序中使用了WebSocket和这个库。它在localhost上运行得很好,但当我将所有这些代码推送到AWS实例时,我无法获得任何消息

我已经完成了自述文件中的所有步骤,将库添加到我的服务器中,我甚至可以通过在两个“客户端”之间发送消息来进行测试。但是,我需要从我的控制器发送消息,并且需要在我的视图中显示这些消息

我的控制器类:

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
require('vendor/autoload.php');

use WebSocket\Client;

public function sendMessage() {
    // Create client object
    $this->client = new Client('ws://0.0.0.0:8282');
    //send null message for verification
    $this->client->send(json_encode(array('user_id' => 1, 'message' => null)));
    //send actual message
    $this->client->send(json_encode(array('user_id' => 1, 'message' => 'Super cool message to myself!')));
}

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

conn.onopen = function (e) {
    conn.send(JSON.stringify(client));
    $('#messages').append('<font color="green">Successfully connected as user ' + client.user_id + '</font><br>');
};

conn.onmessage = function (e) {
    var data = JSON.parse(e.data);
    if (data.message) {
        $('#messages').append(data.user_id + ' : ' + data.message + '<br>');
    }
    if (data.type === 'token') {
        $('#token').html('JWT Token : ' + data.token);
    }
};