Trying to create a websocket link between a phone app and a website


I am creating an app for my capstone project in college. This app will be used as a check-in app that lets the user keep track of appointments and actually check-in for their appointment using their phone.

I am using node and mongodb to create appointments, and for the user to find businesses using the app. The only problem I am having at the moment is establishing the link between the app and the website the businesses will use to monitor check-ins. I figured that I would probably be using for this. I have yet to implement into the app because I am still trying to wrap my head around how to implement this connection.

What I would like to do is have an event handler on the check-in button on the app, and when the user tries to check-in have it send a "notification" to the website. Does anyone have an tips on how I would implement this?

Problem courtesy of: Daniel Leach


Socket.IO is exactly how you do this. You really should do the demo application on the Socket.IO homepage, as it is exactly what you are looking for.

Basically, when the check-in button is pressed, just do something like:

socket.emit('checkin', { /* put data, like an ID, in this object */ });

On the server:

socket.on('checkin', function (data) {
    // Your data passed will be in the data var

Socket.IO serializes all of the data and what not for you. Just emit. That's all there is to it.

Solution courtesy of: Brad


There is currently no discussion for this recipe.

This recipe can be found in it's original form on Stack Over Flow.