Socket.io Example

Hi There!

I am stating to play around with socket.io and I was wondering If anyone had a really simple example of how to get info (llh, fix) from the reach. Having a bit of trouble picking it up from the source code.

I would like to host a web page on the Reach like reachview but displaying coordinates only. Can I just get the coordinates over TCP?

Thanks,

Sam

1 Like

Hi!

To get coordinates via TCP, simply set the solution output to TCP server.

Regarding socket.io:

Here is a snippet from ReachView’s main.js

It creates the socket.io object and initiates connection to the socket.io server. After that, it registers two handlers, one for the disconnect, which shows a warning you can see in the newer versions of ReachView, another one for connect two take the warning away after reconnecting.

// SocketIO namespace:
namespace = "/test";

// initiate SocketIO connection
socket = io.connect("http://" + document.domain + ":" + location.port + namespace);

// say hello on connect
socket.on("connect", function () {
    socket.emit("browser connected", {data: "I'm connected"});
    $( "#popupDisconnected" ).popup( "close");
});

socket.on('disconnect', function(){
    console.log('disconnected');
    $( "#popupDisconnected" ).popup( "open");
});

Pretty straightforward.

And here, in the same file, you can find a handler, which reads the status:

socket.on("coordinate broadcast", function(msg) {
    // check if the browser tab and app tab are active
    if ((active_tab == "Status") && (isActive == true)) {

        console.groupCollapsed('Coordinate msg received:');
            for (var k in msg)
                console.log(k + ':' + msg[k]);
        console.groupEnd();

        updateCoordinateGrid(msg);
    }
});

Don’t hesitate to ask, if you have any more questions!

2 Likes

Thanks Egor. You’re awesome.

I think that this is what I have been needing…

A post was split to a new topic: Connection with Socket.io