Using Socket technology to solve communication problem between guest and hotel

Ramesh Maddila
IDS Next Blog
Published in
4 min readSep 25, 2017

One of the friction points in a guest <-->hotel relationship is “communication”. The definition of “communication” is very broad. There are many inherent and hidden aspects that define “communication” in the context of a guest <-->hotel interaction. These aspects could be — time of communication, response time of hotel to a guest chat message, successful resolution, maintaining a trial / log of the communication for later reference et al.

We recently launched a new product called “StayAhead” — a guest experience management platform.

In this product, we have solved this problem of “communication” by enabling an online chat feature for both guest and the hotel.

While this may sound simple, there are complexities when it comes to execution.

Scenario 1: One to one: This is a simple pattern where a guest chats with a hotel (the hotel can have more than 1 chat users/agents).

Pattern 2: One to many: In this pattern, a single guest can chat with one or more hotels at the same time.

Pattern 3: Many to one: In this pattern, one or more guests chat with a hotel at the same time. To add spice to the equation, we need to ensure two users at the hotel don’t respond to a guest, ability for a hotel user to take over chat from other hotel user, ability to see list of guests a hotel user is chatting with.

Pattern 4: Many to many: In this pattern, one or more guests can chat with one or more hotels at the same time.

In all above scenarios, the chat messages are preserved for later reference. Hotel user or guest are notified about the other party’s response via “typing…” label.

We will see a sneak peak into the technology that we implemented to solve above scenarios.

Socket technology

Normally, a server runs on a specific computer and has a socket that is bound to a specific port number. The server just waits, listening to the socket for a client to make a connection request.

On the client-side: Client knows the hostname of the machine in which server is running and the port number in which server is listening. To make a connection request, the client tries to arrange the calls on the server’s machine and port. The client also needs to identify itself to the server so it binds to a local port number that it will use during this connection. This is usually assigned by the system.

If everything goes well, the server accepts the connection. Upon acceptance, the server gets a new socket bound to the same local port and also has its remote endpoint set to the address and port of the client. It needs a new socket so that it can continue to listen to the original socket for connection requests while tending to the needs of the connected client.

On the client side, if the connection is accepted, a socket is successfully created and the client can use the socket to communicate with the server.

For better understanding let’s take Node.js framework. First, create HTML page that serves out a form and a list of messages, and create a package.json file as manifest that refers the project. It is recommended to place it in a dedicated empty directory (let’s name it “chat-sample”).

{
“name”: “socket-chat-sample”,
“version”: “1.0”,
“description”: “Chat Sample app”,
“dependencies”: {}
}

Now, in order to easily populate the dependencies with the things we need, we will use npm install.

npm install — save express@4.2.7

Now that express is installed we can create an index.js file that will setup our application.

{

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

app.get(‘/’, function(req, res){
res.send(‘<h1>Chat Sample</h1>’);
});

http.listen(8080, function(){
console.log(‘listening on *:8080’);
});

}

In above code snippet,

  1. Express initialises app to be a function handler that you can supply to a HTTP server.
  2. We define a route handler that gets called when we hit our website home
  3. We make the http server listen on port 8080
  4. If you point your browser to http://localhost:8080, you can see “chat sample”

Let me know in comments if you have any questions.

--

--

Ramesh Maddila
IDS Next Blog

Senior Manager at IDS Next. Passionate on innovative technology and product development.