I am trying to do poc for my web based application, I have following
1) A basic node.js/socket.io based server on LINUX that serves basic web page as a client
client.html
<!DOCTYPE html>
<html>
<head>
<script src="/socket.io/socket.io.js"></script>
<script type="text/javascript">
var socket = io.connect("169.xxx.xxx.xx:5000");
socket.on("aServerEvent", function(data)
{
document.getElementById("chatlog").innerHTML = ("<hr/>" +
data['message'] + document.getElementById("chatlog").innerHTML);
});
function sendMessage()
{
var msg = document.getElementById("message_input").value;
socket.emit("aClientEvent", { message : msg});
}
</script>
</head>
<body>
<input type="text" id="message_input"/>
<button onclick="sendMessage()">send</button>
<div id="chatlog"></div>
</body>
</html>
server.js
var app = require('http').createServer(handler),
io = require('socket.io').listen(app),
fs = require('fs')
app.listen(5000,'169.xxx.xxx.xx');
function handler (req, res)
{
fs.readFile("client.html", function (err, data)
{
if (err)
{
res.writeHead(500);
return res.end('Error loading client.html');
}
res.writeHead(200);
res.end(data);
});
}
console.log('Server running at http://169.xxx.xxx.xx:5000/');
io.sockets.on('connection', function(socket)
{
socket.on('aClientEvent', function(data)
{
var newData = "serverResponse: " + data["message"].toUpperCase();
io.sockets.emit("aServerEvent", { message: newData });
});
});
So far so good, I input a text on the webpage(client) that gets read by server which returns upper case text as acknowledgment.
2) Now I want to write a basic C++ program on linux using websocketpp to establish a websocket based connection with my node.js/socket.io server
What is the best way to do that i.e how can I establish a websocket based connection between node.js server and c++ application (websocketpp based) ?
The closest matches I found are..
https://github.com/ebshimizu/socket.io-clientpp
(however uses rapidjson, I want to use libjson only)
https://github.com/uning/socket.io-client-cpp
(this looks like amended version of original websocketpp libraries and has lots of files in src which confuses me if all of them are required)
Any pointer would be much apreciated
Thanks in advance
Solution 1Check that all the Bot Insight services are running. Check that your firewall settings are configured to accept incoming websocket data. Try to use a different web browser. Restart the Bot Insight Visualization and Bot Insight Scheduler services.
In the first case, the Socket will automatically try to reconnect, after a given delay.
Now socket.io has also C++ client. Look here https://github.com/socketio/socket.io-client-cpp There is also a blog post with complete chat example http://socket.io/blog/socket-io-cpp/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With