GithubHelp home page GithubHelp logo

Comments (9)

eidheim avatar eidheim commented on July 20, 2024

If I understand it correctly, version 1.2 works for you, but 1.2.1 does not?

v1.2.1 uses boost::thread, but they should be compatible with std::thread.

Also, what platform do you run it on? And your boost version?

from simple-websocket-server.

pp23 avatar pp23 commented on July 20, 2024

Sorry, v1.1.2 works, v1.2 and v1.2.1 do not. I use Boost 1.59 on a Linux x86_64 system.

from simple-websocket-server.

eidheim avatar eidheim commented on July 20, 2024

You now have to create the endpoints before you run server.start(). This was done to optimise the handling of the requests, that is use precompiled regular expressions. I tested the regular expressions on Debian testing, and this works (based on the latest ws_examples.cpp):

//Example 2: Echo thrice
//  Sending received messages to three times to connected client
//  Test with the following JavaScript on more than one browser windows:
//    var ws=new WebSocket("ws://localhost:8080/echo_thrice");
//    ws.onmessage=function(evt){console.log(evt.data);};
//    ws.send("test");
auto& echo_thrice=server.endpoint["^/echo_thrice/([a-zA-Z0-9]+)/?$"];
echo_thrice.onmessage=[&server](shared_ptr<WsServer::Connection> connection, shared_ptr<WsServer::Message> message) {
    auto message_str=message->string();
    cout << connection->path_match[1].str() << endl;

    auto send_stream1=make_shared<WsServer::SendStream>();
    *send_stream1 << message_str;
    //server.send is an asynchronous function
    server.send(connection, send_stream1, [&server, connection, message_str](const boost::system::error_code& ec) {
        if(!ec) {
            auto send_stream3=make_shared<WsServer::SendStream>();
            *send_stream3 << message_str;
            server.send(connection, send_stream3); //Sent after send_stream1 is sent, and most likely after send_stream2
        }
    });
    //Do not reuse send_stream1 here as it most likely is not sent yet
    auto send_stream2=make_shared<WsServer::SendStream>();
    *send_stream2 << message_str;
    server.send(connection, send_stream2); //Most likely queued, and sent after send_stream1
};

echo_thrice.onopen=[](shared_ptr<WsServer::Connection> connection) {
    cout << connection->path_match[1].str() << endl;
};

Edit: typo

from simple-websocket-server.

eidheim avatar eidheim commented on July 20, 2024

Sorry for using the more complex example 2 instead of example 1.

from simple-websocket-server.

pp23 avatar pp23 commented on July 20, 2024

Ok, is there a way to add enpoints after the server was started?

from simple-websocket-server.

eidheim avatar eidheim commented on July 20, 2024

I think you can do without that using an appropriate regular expression, if not I have to add a function to repopulate opt_endpoint at https://github.com/eidheim/Simple-WebSocket-Server/blob/master/server_ws.hpp#L159. I prefer option 1, to keep things clean.

from simple-websocket-server.

eidheim avatar eidheim commented on July 20, 2024

Also, keep in mind that there has never been a mutex lock on endpoint, so altering it on runtime, that is after server.start(), might lead to strange behaviour.

from simple-websocket-server.

pp23 avatar pp23 commented on July 20, 2024

Ok, I think option 1 will be fine. Thank you for your help :-)

from simple-websocket-server.

eidheim avatar eidheim commented on July 20, 2024

Great, happy to help:)

from simple-websocket-server.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.