joni-jones / yii2-wschat

Online chat based on web sockets
MIT License
99 stars 43 forks source link

Problem Connecting Client to Server #20

Closed chodges closed 8 years ago

chodges commented 8 years ago

Hello:

I've set up and created my server chat controller code. I basically copied exactly what you have in your example in the instructions:

<?php

namespace console\controllers;

use jones\wschat\components\Chat;
use jones\wschat\components\ChatManager;
use Ratchet\Server\IoServer;
use Ratchet\Http\HttpServer;
use Ratchet\WebSocket\WsServer;

class ServerController extends \yii\console\Controller
{
    public function actionRun()
    {
        $manager = \Yii::configure(new ChatManager(), [
            'userClassName' => '\common\models\User' //allow to get users from MySQL or PostgreSQL
        ]);

        $server = IoServer::factory(new HttpServer(new WsServer(new Chat(new ChatManager()))), 3000);
        $server->run();
        echo 'Server was started successfully. Setup logging to get more details.'.PHP_EOL;
    }
}

I then execute the server using this:

 ./yii server/run

First thing I notice is that its not showing me the "Server was started successfully. Setup logging to get more details."

And here is how I have the chat widget set up:

  <?= \jones\wschat\ChatWidget::widget([
        'auth' => true,
        'port' => 3000,
        'user_id' => Yii::$app->user->getIdentity()->id]); ?>

Every time I attempt to connect using the Chat widget it throws up the alert "Something wrong. Connection will be closed". And I can't see anywhere what could be going wrong. Checked my log files and here is the output:

`
    2016-07-24 03:09:04 [-][-][-][info][chat] Connection is established: 167
    in /Applications/MAMP/htdocs/inergycrm/vendor/joni-jones/yii2-wschat/components/Chat.php:41
    in /Applications/MAMP/htdocs/inergycrm/vendor/cboden/ratchet/src/Ratchet/WebSocket/WsServer.php:138
    in /Applications/MAMP/htdocs/inergycrm/vendor/cboden/ratchet/src/Ratchet/WebSocket/WsServer.php:84
2016-07-24 03:09:04 [-][-][-][info][chat] Auth request from rid: 167 and chat: 1
    in /Applications/MAMP/htdocs/inergycrm/vendor/joni-jones/yii2-wschat/components/Chat.php:107
    in /Applications/MAMP/htdocs/inergycrm/vendor/joni-jones/yii2-wschat/components/Chat.php:53
    in /Applications/MAMP/htdocs/inergycrm/vendor/cboden/ratchet/src/Ratchet/WebSocket/Version/RFC6455.php:204

`

Does anyone see anything that could be causing this problem?

joni-jones commented 8 years ago

Hi, @chodges.

First thing I notice is that its not showing me the "Server was started successfully. Setup logging to get more details."

No, this message won't appeared, it will remove it from example code to avoid confusing.

Every time I attempt to connect using the Chat widget it throws up the alert "Something wrong. Connection will be closed"

Do you have any errors in the browser console?

chodges commented 8 years ago

No I don't see any errors in the browser at all. But I do see this error in the server logs now:

2016-07-25 17:22:52 [-][-][-][info][chat] Connection is established: 105
    in /Applications/MAMP/htdocs/inergycrm/vendor/joni-jones/yii2-wschat/components/Chat.php:41
    in /Applications/MAMP/htdocs/inergycrm/vendor/cboden/ratchet/src/Ratchet/WebSocket/WsServer.php:138
    in /Applications/MAMP/htdocs/inergycrm/vendor/cboden/ratchet/src/Ratchet/WebSocket/WsServer.php:84
2016-07-25 17:22:53 [-][-][-][info][chat] Auth request from rid: 105 and chat: 1
    in /Applications/MAMP/htdocs/inergycrm/vendor/joni-jones/yii2-wschat/components/Chat.php:107
    in /Applications/MAMP/htdocs/inergycrm/vendor/joni-jones/yii2-wschat/components/Chat.php:53
    in /Applications/MAMP/htdocs/inergycrm/vendor/cboden/ratchet/src/Ratchet/WebSocket/Version/RFC6455.php:204
2016-07-25 17:22:53 [-][-][-][error][application] ApcCache requires PHP apc extension to be loaded.
    in /Applications/MAMP/htdocs/inergycrm/vendor/joni-jones/yii2-wschat/components/Chat.php:76
    in /Applications/MAMP/htdocs/inergycrm/vendor/cboden/ratchet/src/Ratchet/WebSocket/WsServer.php:158
    in /Applications/MAMP/htdocs/inergycrm/vendor/cboden/ratchet/src/Ratchet/Http/HttpServer.php:70
2016-07-25 17:22:53 [-][-][-][info][chat] Connection is closed: 105
    in /Applications/MAMP/htdocs/inergycrm/vendor/joni-jones/yii2-wschat/components/Chat.php:67
    in /Applications/MAMP/htdocs/inergycrm/vendor/cboden/ratchet/src/Ratchet/WebSocket/WsServer.php:149
    in /Applications/MAMP/htdocs/inergycrm/vendor/cboden/ratchet/src/Ratchet/Http/HttpServer.php:61

Does the chat server require the APC cache be enabled? I don't have it turned on in Apache. Okay even after turning it on I'm still getting the same error messages.

joni-jones commented 8 years ago

The chat extension doesn't require the ApcCache. Please, re-check your cache component in the configuration.

chodges commented 8 years ago

Okay I was able to get it working. Turns out that I had two versions of PHP. One was running my Apache server and the other was running the chat server. Once I used the same version (with cache enabled - because I need it for other things) it came right up!. Thanks for your help!

mehulvadodariya2012 commented 7 years ago

@chodges i have same issue with this widget. echo \jones\wschat\ChatWidget::widget([ 'auth' => true, 'port' => 3000, 'user_id' => Yii::$app->user->getIdentity()->id]); inside view file i have write above code Every time alert popups with msg "Something wrong. Connection will be closed" i'm in my local machine with xampp

Can you please help me ?

chodges commented 7 years ago

Hi @mehulvadodariya2012

Unfortunately I haven't used this code in a long long time so I don't remember what I did to get it working. Ultimately I went with a totally different solution: CometChat. Works great. Sorry I can't be of any assistance.

mehulvadodariya2012 commented 7 years ago

@chodges thanks for quick response :) @joni-jones Are you able to help me ?

joni-jones commented 7 years ago

@mehulvadodariya2012 configure logging and try to find the original error message in the log.