Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

examples folder is missing #1

Closed
Lord-Evil opened this issue Oct 7, 2015 · 2 comments
Closed

examples folder is missing #1

Lord-Evil opened this issue Oct 7, 2015 · 2 comments

Comments

@Lord-Evil
Copy link

Where is it? O.o
I only see these files:

./vendor/morozovsk/
./vendor/morozovsk/yii2-websocket
./vendor/morozovsk/yii2-websocket/README.md
./vendor/morozovsk/yii2-websocket/Connection.php
./vendor/morozovsk/yii2-websocket/console
./vendor/morozovsk/yii2-websocket/console/controllers
./vendor/morozovsk/yii2-websocket/console/controllers/WebsocketController.php
./vendor/morozovsk/yii2-websocket/composer.json
./vendor/morozovsk/websocket
./vendor/morozovsk/websocket/README.md
./vendor/morozovsk/websocket/Server.php
./vendor/morozovsk/websocket/GenericEvent.php
./vendor/morozovsk/websocket/GenericSelect.php
./vendor/morozovsk/websocket/Daemon.php
./vendor/morozovsk/websocket/GenericLibevent.php
./vendor/morozovsk/websocket/composer.json
./vendor/morozovsk/websocket/Test.php

Which also means that in config I should put:

'class' => 'morozovsk\yii2websocket\Connection',

Instead of

'class' => 'morozovsk\websocket\Connection',
@morozovsk
Copy link
Owner

I fix it. Thank you.

@Lord-Evil
Copy link
Author

Вебсокет на PHP слишком муторно выходит у всех. На D 40 строк и все работает, ибо все уже реализовано по человечески во фреймворке Vibe-d. Реккомендую. Вот пример:

module wsocket;

import vibe.d;
import vibe.utils.array;
import std.stdio;

WebSocket[] m_socks;

shared static this(){
    auto router = new URLRouter();
    router.get("/chat/ws",handleWebSockets(&handleConn),).post("/chat/push",&pushMessage);
    auto settings = new HTTPServerSettings;
    settings.port = 8000;
    settings.bindAddresses = ["0.0.0.0"];
    settings.sessionStore = new MemorySessionStore;
    listenHTTP(settings, router);
}

void handleConn(scope WebSocket sock)
{
//  logInfo("Incomming connection! "~sock.request.clientAddress.to!string~" "~sock.request.headers["Sec-WebSocket-Key"]);
    m_socks~=sock;
    while (sock.waitForData()) {
        auto msg = sock.receiveText();
        //can do something with incomming message
    }
//  logInfo("Connection closed! "~sock.request.headers["Sec-WebSocket-Key"]);
    m_socks.removeFromArray(sock);
    sock=null;
}
void pushMessage(HTTPServerRequest req, HTTPServerResponse res){
    if(m_socks.length>0){
        foreach(WebSocket s_sock;m_socks){
            Json data = req.json;
            s_sock.send(data.toString());
        }
        res.writeJsonBody(["status":"success"]);
    }else{
        res.writeJsonBody(["status":"fail"]);
    }
}

/chat/ws - сам вебсокет
/chat/push - морда для того, чтоб PHP скрипт его пинал. Вот для Yii можно действительно сделать, как у тебя модель для отправки вызова откуда угодно, все.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants