CZML via Sockets.IO

Hello,

I would like to use websockets to send CZML to a web-page containing the Cesium viewer. To do so, I have been using this topic as a reference. A search for similar topics didn’t turn anything up. Until now I have been using PHP but need a full duplex link.

The server code is in a dedicated file and served by Node.js The problem is that I can’t get it to exchange CZML data. I’m posting it here rather than on a Javascript forum in the hope that someone will have previously achieved this in Cesium and might be kind enough to help.

Client:

In the section of the client html:

``

In the section of the client html:
var socket = io.connect(‘http://localhost:80’);

socket.on(‘connect’, () => {

console.log(‘Successfully connected!’);

}
);

socket.on(‘czmlObject’, function(msg){

console.log(msg);

}

);

``

Server:

var app = require(‘express’)();

var http = require(‘http’).Server(app);

var io = require(‘socket.io’)(http);

io.on(‘connection’, function(socket){

 console.log('a user connected'); 
                                 socket.broadcast.emit('czmlObject', 'rhubarb'); 

}

);

http.listen(80, function(){

console.log(‘listening on *:80’);

}

);

``

When I open/refresh the client html (containing the Cesium viewer) the ‘successfully connected!’ message is shown in the developer console and the ‘a user connected’ message in the Command Prompt…

Believe it or not, I’ve spent a couple of days trying to get the websocket approach to work. This is a cri de coeur for any help or example code that might get me going in the right direction.

Thanks in advance,

Hugh

I’m an idiot:

socket.broadcast.emit

``

sends to all other clients.

socket.emit

``

works perfectly.

D’Oh!

Hi Hugh, glad you got this figured out regardless! Thanks for the update.

Now its working, I’ve found it really useful, especially being able to send data as JSON objects.

Neat! If you are interested in writing a blog post on the integration.

I’ve sent something to your gmail address.