Comments (9)
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.
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.
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.
Sorry for using the more complex example 2 instead of example 1.
from simple-websocket-server.
Ok, is there a way to add enpoints after the server was started?
from simple-websocket-server.
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.
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.
Ok, I think option 1 will be fine. Thank you for your help :-)
from simple-websocket-server.
Great, happy to help:)
from simple-websocket-server.
Related Issues (20)
- [suggest] Send/Broadcast and Text/BinaryMode HOT 1
- Standalone Asio not found - but asio.hpp is present HOT 4
- re again WssClient::start causes on_error HOT 10
- When I use Google Chrome it happend a error. HOT 3
- exception thrown in server start (boost related) HOT 4
- Connection Timeout HOT 2
- Create example on how to stream data to a client HOT 1
- Unable to compile against standalone asio HOT 1
- How to stop the server? HOT 3
- Installed but ws_examples throws an error HOT 1
- Support for the Sec-WebSocket-Protocol field HOT 3
- fatal error C1083: Cannot open include file : 'pthread.h': No such file or directory HOT 1
- Messages split among frames aren't reasembled HOT 25
- Openssl wants void* instead of char* in 0x1000115fL HOT 1
- how to initiate send message from client HOT 3
- Client request error: End of file
- Access violation exeption HOT 3
- gdiplus
- Can't use wss client HOT 5
- Integration with Simple-Web-Server HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from simple-websocket-server.