{"id":2899,"date":"2015-03-26T12:15:38","date_gmt":"2015-03-26T10:15:38","guid":{"rendered":"http:\/\/www.webcodegeeks.com\/?p=2899"},"modified":"2017-12-19T14:08:13","modified_gmt":"2017-12-19T12:08:13","slug":"html5-websocket-example","status":"publish","type":"post","link":"https:\/\/www.webcodegeeks.com\/html5\/html5-websocket-example\/","title":{"rendered":"HTML5 websocket example"},"content":{"rendered":"<p>In this article I will present you the WebSocket feature of HTML5.<\/p>\n<p>We will first describe the API with small examples, then I&#8217;ll try to create a small app using the API.<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n[ulp id=&#8217;tgm4cmEWcKUikZNn&#8217;]<\/p>\n<h2>1. Presentation<\/h2>\n<p>WebSocket will allow you to create a full connection to a server, this will allow the server to notify (push) data to the connected client(s).<\/p>\n<p>Ajax requests are <em>&#8220;One Way&#8221;<\/em>, it means that all the requests are initiated by the client. When the server has send the response, it (the server) will clause the connection.<\/p>\n<p>Imagine an application that will need to notify users when something has change on the server, for example a user connection in a chat system, or a new task added in a share task list system.<\/p>\n<p>Before WebSockets, the only way to create a notification mechanism on a web site, was to make an ajax request every two or three seconds, or to create <a href=\"http:\/\/en.wikipedia.org\/wiki\/Push_technology#Long_polling\" target=\"_blank\">long polling<\/a> requests.<\/p>\n<p>Now we can on each client, create a connection, this mean the server will maintain connexion with the client.<\/p>\n<p>Connections are always initiated (the first call) by the client.<\/p>\n<h3>1.1 Compatibility<\/h3>\n<p>As you can imagine old browsers will not allow you to use this feature, but all modern browsers are compatible, you can check your browser by visiting the <a href=\"http:\/\/caniuse.com\/#feat=websockets\">CanIUse Web Site<\/a>.<\/p>\n<p>And in your application you can test the presence of the WebSocket Api :<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nif( window.WebSocket ){\r\n\/\/ supported\r\n}else{\r\n\/\/ not supported\r\n}\r\n<\/pre>\n<p>This is quite simple &#8230; nothing to explain here.<\/p>\n<h3>1.2 Server Implementation<\/h3>\n<p>The WebSocket feature has to be present on the browser, but it must be accepted by the server too.<\/p>\n<p>There is many server implementations in different languages, here is a non exhaustive list :<\/p>\n<h4>Node.js<\/h4>\n<ul>\n<li><a href=\"http:\/\/socket.io\/\" target=\"_blank\">Socket.IO<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/Worlize\/WebSocket-Node\" target=\"_blank\">WebSocket-Node<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/einaros\/ws\" target=\"_blank\">ws<\/a><\/li>\n<\/ul>\n<h4>Java<\/h4>\n<ul>\n<li><a href=\"https:\/\/grizzly.java.net\/websockets.html\" target=\"_blank\">Grizzly<\/a><\/li>\n<li><a href=\"http:\/\/tomcat.apache.org\/tomcat-7.0-doc\/web-socket-howto.html\" target=\"_blank\">Apache Tomcat 7<\/a><\/li>\n<li><a href=\"http:\/\/wiki.eclipse.org\/Jetty\/Feature\/WebSockets\" target=\"_blank\">Jetty<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/Atmosphere\" target=\"_blank\">Atmosphere<\/a><\/li>\n<\/ul>\n<h4>Ruby<\/h4>\n<ul>\n<li><a href=\"http:\/\/github.com\/igrigorik\/em-websocket\">EventMachine<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/faye\/faye-websocket-ruby\">Faye WebSocket<\/a><\/li>\n<\/ul>\n<h4>Python<\/h4>\n<ul>\n<li><a href=\"http:\/\/code.google.com\/p\/pywebsocket\/\">pywebsocket<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/facebook\/tornado\">Tornado<\/a><\/li>\n<\/ul>\n<h4>PHP<\/h4>\n<ul>\n<li><a href=\"http:\/\/socketo.me\/\">Rachet<\/a><\/li>\n<li><a href=\"https:\/\/code.google.com\/p\/phpwebsocket\/\">Php Websocket<\/a><\/li>\n<\/ul>\n<p>In our example we will use a PHP implementation.<\/p>\n<h2>2. The API<\/h2>\n<p>So know let see how the API works. (Remember to check if the WebSocket is supported by the browser).<\/p>\n<h3>2.1 Create the connection<\/h3>\n<p>The simplest way to create a connection is :<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nvar socket = new WebSockect('ws:\/\/localhost:8080');\r\n<\/pre>\n<p>The Constructor parameters are : <code>url<\/code>, and optionally you can add one or more <code>protocols<\/code>.<\/p>\n<p>The url scheme : <code>ws:\/\/<\/code> (and <code>wss:\/\/<\/code> for secure connections) was introduced with the WebSocket Api, this scheme tell the browser to negotiate a WebSocket connection.<\/p>\n<p>The <code>protocol<\/code> parameter can be, ommited, or a single string or an array of protocol strings. This will indicate sub-protocols implemented by a server, so that a single server can implement multiple WebSocket sub-protocols (for example, you might want one server to be able to handle different types of interactions depending on the specified protocol). If you don&#8217;t specify a protocol string, an empty string is assumed.<\/p>\n<h3>2.2 Attributes <\/h3>\n<p>The WebSocket object has three attributes :<\/p>\n<ul>\n<li><code>url<\/code>, the url passed to the constructor, it&#8217;s a <em>readonly<\/em> attribute.<\/li>\n<li><code>readyState<\/code>, this attribute contains a numerical value that represents the state of the connection.<br \/>\n        It&#8217;s a <em>readonly<\/em> attribute. It can have the following values :<\/p>\n<ul>\n<li><code>CONNECTING<\/code>, <em>(numeric value 0)<\/em> The connection has not yet been established.<\/li>\n<li><code>OPEN<\/code>, <em>(numeric value 1)<\/em> The WebSocket connection is established and communication<br \/>\n                is possible.\n            <\/li>\n<li><code>CLOSING<\/code>, <em>(numeric value 2)<\/em> The connection is going through the closing handshake.\n            <\/li>\n<li><code>CLOSED<\/code>, <em>(numeric value 3)<\/em> The connection has been closed or could not be opened.\n            <\/li>\n<\/ul>\n<\/li>\n<li><code>protocol<\/code>, initially an empty string. After connection established, the value might change, it&#8217;s a<br \/>\n        <em>readonly<\/em> attribute.\n    <\/li>\n<\/ul>\n<h3>2.3 Methods<\/h3>\n<p><code>WebSocket<\/code> has two methods :<\/p>\n<ul>\n<li><code>send(DOMString data)<\/code>, This method will send its <code>data<\/code> parameter to the server, the data<br \/>\n        must be a string.\n    <\/li>\n<li><code>close()<\/code>, calling this method will end the connection.<\/li>\n<\/ul>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nvar socket = new WebSockect('ws:\/\/localhost:8080');\r\nsocket.send(&quot;Somme Message to send to the server&quot;);\r\nsocket.close();\r\n<\/pre>\n<h3>2.4 Events<\/h3>\n<p><code>WebSocket<\/code> introduced some events to interact with behaviour, like receiving some data from the server.<\/p>\n<ul>\n<li><code>open<\/code>, or as a function :<code>onopen<\/code>, is fired (or called) when the connection is<br \/>\n        established.\n    <\/li>\n<li><code>message<\/code>, or as a function :<code>onmessage<\/code>, is fired (or called) when a message is<br \/>\n        received..\n    <\/li>\n<li><code>error<\/code>, or as a function :<code>onerror<\/code>, is fired (or called) when an error occured.<\/li>\n<li><code>close<\/code>, or as a function :<code>onclose<\/code>, is fired (or called) when the connection is close.\n    <\/li>\n<\/ul>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nvar socket = new WebSockect('ws:\/\/localhost:8080');\r\nsocket.addEventListener('open', function(){\r\n    console.log(&quot;Connection established, handle with event&quot;);\r\n});\r\nsocket.onopen = function(){\r\n    console.log(&quot;Connection established, handle with function&quot;);\r\n};\r\nsocket.close();\r\n<\/pre>\n<p>The two <code>open<\/code> handler have the same behaviour. Personally I prefer using the <code>addEventListener<\/code> way.<\/p>\n<h2>3. The Real World Example<\/h2>\n<p>As we now know how the <code>WebSocket<\/code> object is used we can create a <em>&#8220;real world&#8221;<\/em> example. In this example we will create a shared <em>&#8220;Todo List&#8221;<\/em>.<\/p>\n<p>Imagine an application that allow you to create an online Todo List, but many user might add some tasks to the list, and you want everyone to be notified that someone added a task.<\/p>\n<p>So we will create a basic list with a small form to add some tasks. As i already made an article with a todo list example (see it <a href=\"http:\/\/www.webcodegeeks.com\/html5\/html5-offline-web-application-example\/\">HTML5 offline web application example<\/a>) so i will reuse some JavaScript Code.<\/p>\n<h3>3.1 The base application<\/h3>\n<p>As I told you, I&#8217;ve already created a Todo List, but only a Single Page Application, with no interactions, here is the base code:<\/p>\n<h4>The HTML Code :<\/h4>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;!DOCTYPE html&gt;\r\n&lt;html&gt;\r\n&lt;head lang=&quot;en&quot;&gt;\r\n    &lt;meta charset=&quot;UTF-8&quot;&gt;\r\n    &lt;title&gt;Task List Example&lt;\/title&gt;\r\n    &lt;link href=&quot;css\/style.css&quot; rel=&quot;stylesheet&quot;\/&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n&lt;div id=&quot;wrapper&quot;&gt;\r\n    &lt;form id=&quot;taskform&quot;&gt;\r\n        &lt;input type=&quot;hidden&quot; id=&quot;task_id&quot; value=&quot;-1&quot;\/&gt;\r\n        &lt;input type=&quot;text&quot; id=&quot;task&quot; placeholder=&quot;Add a Task ...&quot;\/&gt;\r\n        &lt;input type=&quot;submit&quot; value=&quot;Add&quot;\/&gt;\r\n    &lt;\/form&gt;\r\n    &lt;ul id=&quot;tasklist&quot;&gt;&lt;\/ul&gt;\r\n    &lt;button id=&quot;reset&quot;&gt;Clear All Tasks&lt;\/button&gt;\r\n&lt;\/div&gt;\r\n&lt;script src=&quot;js\/zepto.min.js&quot;&gt;&lt;\/script&gt;\r\n&lt;script src=&quot;js\/script.js&quot;&gt;&lt;\/script&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre>\n<p>This is a simple web page, with a form (<code>#taskform<\/code>), that contains a text field to add the task description, and a submit button. The page also contains an area for the tasks (<code>#tasklist<\/code>). The reset button is here to empty the task list.<\/p>\n<h4>The JavaScript Code :<\/h4>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n\/**\r\n* @author R\u00e9mi Goyard\r\n*\/\r\n$(function () {\r\n\r\n    \/**\r\n    *\r\n    * The Tasks Object\r\n    *\/\r\n    var tasks = {\r\n        \/**\r\n        * Reset the form inputs\r\n        *\/\r\n        resetForm: function () {\r\n            $('#task').val('');\r\n            $('#task_id').val(-1);\r\n        },\r\n\r\n        \/**\r\n        * create the element in the task list from the task object\r\n        *\r\n        * @param task { id : (int) the task id, task : (string) the task description}\r\n        *\/\r\n        createTask: function (task) {\r\n            var $li = tasks.createElemnt(task);\r\n            $('#tasklist').append($li);\r\n            tasks.resetForm();\r\n        },\r\n\r\n        \/**\r\n        * remove a task from it's id\r\n        *\r\n        * @param id\r\n        *\/\r\n        remove: function (id) {\r\n            var taskId = $('#task_id').val();\r\n            if (taskId === id) {\r\n                tasks.resetForm();\r\n            }\r\n            $('#' + id).remove();\r\n        },\r\n\r\n        \/**\r\n        * Edit a task, fill the form inputs from the Dom Element\r\n        * @param spanEl\r\n        *\/\r\n        edit: function (spanEl) {\r\n            var $li = $(spanEl).parent();\r\n            var taskId = $(spanEl).parent().attr('id');\r\n            var $taskElement = $('#task');\r\n            $taskElement.val($(spanEl).text()).focus();\r\n            $('#task_id').val(taskId);\r\n            $li.addClass(&quot;edited&quot;);\r\n        },\r\n\r\n        \/**\r\n        * Replace a task by another (used in edit)\r\n        * @param task\r\n        *\/\r\n        replace: function (task) {\r\n            var $li = tasks.createElemnt(task);\r\n            $('#' + task.id).replaceWith($li);\r\n            tasks.resetForm();\r\n        },\r\n\r\n        \/**\r\n        * Reset the list (empty the list container)\r\n        *\/\r\n        reset:function(){\r\n            $(&quot;#tasklist&quot;).html('');\r\n        },\r\n\r\n        \/**\r\n        * Create the li element to add or replace in the Task List\r\n        * @param task\r\n        * @returns {*|jQuery|HTMLElement}\r\n        *\/\r\n        createElemnt:function(task){\r\n            return $('&lt;li id=&quot;' + task.id + '&quot;&gt;&lt;div&gt;' + task.task + '&lt;\/div&gt;&lt;span&gt;&lt;a href=&quot;#&quot; class=&quot;delete&quot;&gt;delete&lt;\/a&gt;&lt;\/span&gt;&lt;\/li&gt;');\r\n        }\r\n    };\r\n\r\n\r\n    \/**\r\n    * Generate a unique String based on timestamp\r\n    * @returns {string}\r\n    *\/\r\n    function createUniqId() {\r\n        return '_' + (new Date().getTime()).toString(16);\r\n    }\r\n\r\n    \/**\r\n    * The init function, that will load form events.\r\n    * And manage interaction between user interface and server.\r\n    *\r\n    * @param taskList The array of tasks\r\n    *\/\r\n    function init(taskList) {\r\n\r\n        \/**\r\n        Manage the Form Submission\r\n        For Adding or editing task\r\n        *\/\r\n        $(&quot;#taskform&quot;).submit(function (e) {\r\n            e.preventDefault();\r\n            var task = $('#task').val();\r\n            var taskId = $('#task_id').val();\r\n            var taskObj = {id: taskId, task: task};\r\n            if (taskObj.id == -1) {\r\n                \/\/ This is a new task submited\r\n                taskObj.id = createUniqId();\r\n                tasks.createTask(taskObj);\r\n            } else {\r\n                \/\/ this is an existing task\r\n                tasks.replace(taskObj);\r\n            }\r\n        });\r\n\r\n        \/**\r\n        * Click On the Reset Button\r\n        *\/\r\n        $('#reset').click(function () {\r\n            tasks.reset();\r\n        });\r\n\r\n\r\n        var $taskList =$(&quot;#tasklist&quot;);\r\n\r\n        \/**\r\n        * Click on a delete Link to delete list item\r\n        *\/\r\n        $taskList.on('click', 'a.delete', function(e){\r\n            e.stopPropagation();\r\n            var id = $(this).parents('li').attr('id');\r\n            tasks.remove(id);;\r\n        });\r\n\r\n        \/**\r\n        * DblClick on a Task Link to edit the list item\r\n        *\/\r\n        $taskList.on('dblclick', 'li &gt; div', function() {\r\n            tasks.edit(this);\r\n        });\r\n\r\n\r\n        \/**\r\n        * Initialise the list with the initial (from parameter) tasklist array\r\n        *\/\r\n        for (var i = 0; i &lt; taskList.length; i++) {\r\n            tasks.createTask(taskList&#x5B;i]);\r\n        }\r\n    }\r\n\r\n\r\n    \/**\r\n    Run the Application  with empty Task list\r\n    *\/\r\n    init(&#x5B;]);\r\n})();\r\n<\/pre>\n<p>The code is fully documented so I think there&#8217;s no needs to describe it.<\/p>\n<p>This will create a web page like that :<\/p>\n<figure id=\"attachment_2942\" aria-describedby=\"caption-attachment-2942\" style=\"width: 785px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/03\/online.png\"><img decoding=\"async\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/03\/online.png\" alt=\"HTML5 Websocket Example\" width=\"785\" height=\"526\" class=\"size-full wp-image-2942\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/03\/online.png 785w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/03\/online-300x201.png 300w\" sizes=\"(max-width: 785px) 100vw, 785px\" \/><\/a><figcaption id=\"caption-attachment-2942\" class=\"wp-caption-text\">HTML5 Websocket Example<\/figcaption><\/figure>\n<h3>3.2 The Message mechanism<\/h3>\n<p>As we need to communicate with a server in order to make some actions, we will need to create a simple message mechanism.<\/p>\n<p>The actions we need are :<\/p>\n<ul>\n<li><code>LIST<\/code>, this action will be send by the server to the client just after the client connection.<\/li>\n<li><code>ADD<\/code>, this action will be first send by the client to server, just after adding a new task,<br \/>\n        the server persists the task and then send the action to all other clients.<\/li>\n<li><code>DELETE<\/code>, this action will be first send by the client to server, just after deleting a task,<br \/>\n        the server persists the task and then send the action to all other clients.<\/li>\n<li><code>EDIT<\/code>, this action will be first send by the client to server, just after updating a task,<br \/>\n        the server persists the task and then send the action to all other clients.<\/li>\n<li><code>CLEAR<\/code>, this action will be first send by the client to server, just after clicking on the <em>Reset button<\/em>,<br \/>\n        the server reset the tasks datas, and then send the action to all other clients.<\/li>\n<\/ul>\n<p>So i&#8217;ve created a message like that :<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nvar message = {\r\n    action:'ACTION_CONSTANT',\r\n    data:{} \/\/ the data to send\r\n};\r\n<\/pre>\n<p>So let start a server static object, at the end of the javascript file (just after the line with <code>init([]);<\/code>) create the following code :<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nvar server = {\r\n    ACTION: {\r\n        LIST: 0,\r\n        ADD: 1,\r\n        DELETE: 2,\r\n        EDIT: 3,\r\n        CLEAR:4\r\n        },\r\n    createMessage: function(action, message){\r\n        return {action:action, data:message};\r\n    }\r\n};\r\n<\/pre>\n<p>The values of the <code>server.ACTION<\/code> constants are shared with the server.<\/p>\n<p>So now we can start to communicate with the server.<\/p>\n<h3>3.3 Server<\/h3>\n<h4>Run the server<\/h4>\n<p>As i said earlier I created a server Application using a PHP implementation based on <a href=\"http:\/\/socketo.me\/\">Ratchet<\/a>.<\/p>\n<p>The source application is in the Download bundle, to run the server application go in the server directory then retrieve the dependencies, and run the application.<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\ncd DOWNLOADED_BUNDLE\/server\r\ncomposer install\r\nphp index.php\r\n<\/pre>\n<blockquote><p>\n    <strong>NOTE<\/strong> : If you&#8217;re not familiar with composer, go to the online documentation : <a href=\"https:\/\/getcomposer.org\/\">https:\/\/getcomposer.org\/<\/a>.\n<\/p><\/blockquote>\n<blockquote><p>\n    <strong>NOTE<\/strong> : the server is listening on the 8080 port.\n<\/p><\/blockquote>\n<h2>4. Adding the server integration<\/h2>\n<h3>4.1 Connect to the server<\/h3>\n<p> After the server is running, we can connect to it.<\/p>\n<p> So we can augment the <code>server<\/code> object :<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nvar server = {\r\n    socket:null,\r\n    ACTION: {\r\n        LIST: 0,\r\n        ADD: 1,\r\n        DELETE: 2,\r\n        EDIT: 3,\r\n        CLEAR:4\r\n    },\r\n    createMessage: function(action, message){\r\n        return {action:action, data:message};\r\n    },\r\n    init:function(){\r\n        server.socket = new WebSocket(&quot;ws:\/\/localhost:8080&quot;);\r\n    }\r\n};\r\n<\/pre>\n<p>So a simple call to <code>server.init();<\/code> will connect the client to the server application.<\/p>\n<h3>4.2 Listen to messages<\/h3>\n<p>Once the client is connected to the server we can start to listen the messages sent by the server :<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nvar server = {\r\n    socket:null,\r\n    ACTION: {\r\n        LIST: 0,\r\n        ADD: 1,\r\n        DELETE: 2,\r\n        EDIT: 3,\r\n        CLEAR:4\r\n    },\r\n    createMessage: function(action, message){\r\n        return {action:action, data:message};\r\n    },\r\n    init:function(){\r\n        server.socket = new WebSocket(&quot;ws:\/\/localhost:8080&quot;);\r\n        server.on('message', function(message){\r\n\r\n        });\r\n    }\r\n};\r\n<\/pre>\n<p>As all messages received from the server are in string format we need to parse the JSON string, and then we will delegate the work to dedicated function.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nvar server = {\r\n    socket:null,\r\n    ACTION: {\r\n        LIST: 0,\r\n        ADD: 1,\r\n        DELETE: 2,\r\n        EDIT: 3,\r\n        CLEAR:4\r\n    },\r\n    createMessage: function(action, message){\r\n        return {action:action, data:message};\r\n    },\r\n    init:function(){\r\n        server.socket = new WebSocket(&quot;ws:\/\/localhost:8080&quot;);\r\n        server.on('message', function(message){\r\n            var messageObj = JSON.parse(message.data);\r\n            server.receive(messageObj);\r\n        });\r\n    },\r\n    receive:function(messageObj){\r\n        \/\/ Handle dispatching\r\n    }\r\n};\r\n<\/pre>\n<h3>4.3 Initialize the list from server data<\/h3>\n<p>Now we will &#8220;connect&#8221; the User interface and the server, first we need to add all the existing tasks (from the server) to the <code>#tasklist<\/code> container on the user interface.<\/p>\n<p>As we&#8217;ve seen earlier, the <code>LIST<\/code> action is send by the server with all the tasks, so we will call the <code>init()<\/code> function the the tasks received from the server :<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nvar server = {\r\n    socket:null,\r\n        ACTION: {\r\n        LIST: 0,\r\n        ADD: 1,\r\n        DELETE: 2,\r\n        EDIT: 3,\r\n        CLEAR:4\r\n    },\r\n    createMessage: function(action, message){\r\n        return {action:action, data:message};\r\n    },\r\n    init:function(){\r\n        server.socket = new WebSocket(&quot;ws:\/\/localhost:8080&quot;);\r\n        server.on('message', function(message){\r\n            var messageObj = JSON.parse(message.data);\r\n            server.receive(messageObj);\r\n        });\r\n    },\r\n    receive:function(messageObj){\r\n        if (messageObj.action === server.ACTION.LIST) {\r\n            init.call(null, messageObj.message);\r\n        }\r\n    }\r\n};\r\n<\/pre>\n<p>And then replace the line :<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\ninit(&#x5B;]);\r\n<\/pre>\n<p>with :<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nserver.init();\r\n<\/pre>\n<h3>4.4 add, edit, and delete a task<\/h3>\n<p>So now the application loads data from the server. Let&#8217;s implement the other actions.<\/p>\n<h4>Add a Task<\/h4>\n<p>Adding a task is made on form submission, when the <code>taskId<\/code> is equal to <code>-1<\/code>.<\/p>\n<p>So let&#8217;s add a call to the <code>server.add(task)<\/code> function just after the task is added to the DOM.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n\/\/ ...\r\n\r\n\/**\r\nManage the Form Submission\r\nFor Adding or editing task\r\n*\/\r\n$(&quot;#taskform&quot;).submit(function (e) {\r\n    e.preventDefault();\r\n    var task = $('#task').val();\r\n    var taskId = $('#task_id').val();\r\n    var taskObj = {id: taskId, task: task};\r\n    if (taskObj.id == -1) {\r\n        \/\/ This is a new task submited\r\n        taskObj.id = createUniqId();\r\n        tasks.createTask(taskObj);\r\n        server.add(taskObj); \/\/ here is the Addition\r\n    } else {\r\n        \/\/ this is an existing task\r\n        tasks.replace(taskObj);\r\n    }\r\n});\r\n\r\n\/\/ ...\r\n<\/pre>\n<p>Then implement the <code>add<\/code> function to the <code>server<\/code> object to send the message to the server.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nvar server = {\r\n    socket:null,\r\n        ACTION: {\r\n        LIST: 0,\r\n        ADD: 1,\r\n        DELETE: 2,\r\n        EDIT: 3,\r\n        CLEAR:4\r\n    },\r\n    createMessage: function(action, message){\r\n        return {action:action, data:message};\r\n    },\r\n    init:function(){\r\n        server.socket = new WebSocket(&quot;ws:\/\/localhost:8080&quot;);\r\n        server.on('message', function(message){\r\n            var messageObj = JSON.parse(message.data);\r\n            server.receive(messageObj);\r\n        });\r\n    },\r\n    receive:function(messageObj){\r\n        if (messageObj.action === server.ACTION.LIST) {\r\n            init.call(null, messageObj.message);\r\n        }\r\n    },\r\n    add: function (task) {\r\n        server.send(server.ACTION.ADD,task);\r\n    },\r\n    send: function (action, message) {\r\n        var data = server.createMessage(action, message);\r\n        server.socket.send(JSON.stringify(data));\r\n    }\r\n};\r\n<\/pre>\n<p>Now the task is sent to the server but we also have to implement the task reception from the server. When the task is sent to the server, after it has persisted it, the server will send the added task to other clients this the reception of this push we have to implement :<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nvar server = {\r\n    socket:null,\r\n        ACTION: {\r\n        LIST: 0,\r\n        ADD: 1,\r\n        DELETE: 2,\r\n        EDIT: 3,\r\n        CLEAR:4\r\n    },\r\n    createMessage: function(action, message){\r\n        return {action:action, data:message};\r\n    },\r\n    init:function(){\r\n        server.socket = new WebSocket(&quot;ws:\/\/localhost:8080&quot;);\r\n        server.on('message', function(message){\r\n            var messageObj = JSON.parse(message.data);\r\n            server.receive(messageObj);\r\n        });\r\n    },\r\n    receive:function(messageObj){\r\n        if (messageObj.action === server.ACTION.LIST) {\r\n            init.call(null, messageObj.message);\r\n        }\r\n        \/\/ Manage the reception of the task  received from the server\r\n        if( messageObj.action === server.ACTION.ADD){\r\n            tasks.createTask(messageObj.message);\r\n        }\r\n    },\r\n    add: function (task) {\r\n        server.send(server.ACTION.ADD,task);\r\n    },\r\n    send: function (action, message) {\r\n        var data = server.createMessage(action, message);\r\n        server.socket.send(JSON.stringify(data));\r\n    }\r\n};\r\n<\/pre>\n<h4>The other actions<\/h4>\n<p>As we did it for the <code>ADD<\/code> action, here is the modifications added to the <code>init()<\/code> function :<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n\/**\r\n* The init function, that will load form events.\r\n* And manage interaction between user interface and server.\r\n*\r\n* @param taskList The array of tasks\r\n*\/\r\nfunction init(taskList) {\r\n    $(&quot;#taskform&quot;).submit(function (e) {\r\n        e.preventDefault();\r\n        var task = $('#task').val();\r\n        var taskId = $('#task_id').val();\r\n        var taskObj = {id: taskId, task: task};\r\n        if (taskObj.id == -1) {\r\n            \/\/ This is a new task submited\r\n            taskObj.id = createUniqId();\r\n            tasks.createTask(taskObj);\r\n            server.add(taskObj);\r\n        } else {\r\n            \/\/ this is an existing task\r\n            tasks.replace(taskObj);\r\n            server.update(taskObj); \/\/ Concern the EDIT action\r\n        }\r\n    });\r\n    $('#reset').click(function () {\r\n        tasks.reset();\r\n        server.reset(); \/\/ Concern the CLEAR action\r\n    });\r\n\r\n    var $taskList =$(&quot;#tasklist&quot;);\r\n    $taskList.on('click', 'a.delete', function(e){\r\n        e.stopPropagation();\r\n        var id = $(this).parents('li').attr('id');\r\n        tasks.remove(id);\r\n        server.remove(id); \/\/ Concern the DELETE action\r\n    });\r\n\r\n    $taskList.on('dblclick', 'li &gt; div', function() {\r\n        tasks.edit(this);\r\n    });\r\n\r\n    for (var i = 0; i &lt; taskList.length; i++) {\r\n        tasks.createTask(taskList&#x5B;i]);\r\n    }\r\n}\r\n<\/pre>\n<p>And the finished <code>server<\/code> object :<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nvar server = {\r\n    socket: null,\r\n    ACTION: {\r\n        LIST: 0,\r\n        ADD: 1,\r\n        DELETE: 2,\r\n        EDIT: 3,\r\n        CLEAR:4\r\n    },\r\n    init: function () {\r\n        server.socket = new WebSocket(&quot;ws:\/\/localhost:8080&quot;);\r\n        server.socket.addEventListener('message', function (message) {\r\n            var messageObj = JSON.parse(message.data);\r\n            server.receive(messageObj, callback);\r\n        });\r\n    },\r\n    receive:function(messageObj){\r\n        if (messageObj.action === server.ACTION.LIST) {\r\n            init.call(null, messageObj.message);\r\n        }\r\n        if( messageObj.action === server.ACTION.ADD){\r\n         tasks.createTask(messageObj.message);\r\n        }\r\n        if( messageObj.action === server.ACTION.DELETE){ \/\/ Concern the DELETE action\r\n            tasks.remove(messageObj.message.id);\r\n        }\r\n        if( messageObj.action === server.ACTION.EDIT){ \/\/ Concern the EDIT action\r\n            tasks.replace(messageObj.message);\r\n        }\r\n        if( messageObj.action === server.ACTION.CLEAR){ \/\/ Concern the CLEAR action\r\n            tasks.reset();\r\n        }\r\n    },\r\n    add: function (task) {\r\n        server.send(server.ACTION.ADD,task);\r\n    },\r\n    remove: function (id) { \/\/ Concern the DELETE action\r\n        server.send(server.ACTION.DELETE, {id:id});\r\n    },\r\n    update:function(task){ \/\/ Concern the EDIT action\r\n        server.send(server.ACTION.EDIT, task);\r\n    },\r\n    reset:function(){ \/\/ Concern the CLEAR action\r\n        server.send(server.ACTION.CLEAR, &quot;&quot;);\r\n    },\r\n    createMessage: function(action, message){\r\n        return {action:action, data:message};\r\n    },\r\n    send: function (action, message) {\r\n        var data = server.createMessage(action, message);\r\n        server.socket.send(JSON.stringify(data));\r\n    }\r\n};\r\n<\/pre>\n<p>And it&#8217;s finished !!!<\/p>\n<p>In order to test simply open the web page with two different browsers, you will see all the modifications made on a browser being applied to all other browsers.<\/p>\n<h2>5. Download<\/h2>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the full source code of this example here : <a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/03\/html5_websocket_example.zip\"><strong>html5 websocket example<\/strong><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this article I will present you the WebSocket feature of HTML5. We will first describe the API with small examples, then I&#8217;ll try to create a small app using the API. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [ulp id=&#8217;tgm4cmEWcKUikZNn&#8217;] 1. Presentation WebSocket will allow you to create a full connection to a &hellip;<\/p>\n","protected":false},"author":46,"featured_media":914,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[119],"class_list":["post-2899","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-html5","tag-websocket"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>HTML5 websocket example - Web Code Geeks - 2026<\/title>\n<meta name=\"description\" content=\"In this article i will present you the WebSocket feature of HTML5. We will first describe the API, then i&#039;ll try to create a small app example using the API.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.webcodegeeks.com\/html5\/html5-websocket-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"HTML5 websocket example - Web Code Geeks - 2026\" \/>\n<meta property=\"og:description\" content=\"In this article i will present you the WebSocket feature of HTML5. We will first describe the API, then i&#039;ll try to create a small app example using the API.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.webcodegeeks.com\/html5\/html5-websocket-example\/\" \/>\n<meta property=\"og:site_name\" content=\"Web Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webcodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2015-03-26T10:15:38+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2017-12-19T12:08:13+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/html5-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Remi Goyard\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@mimiz33\" \/>\n<meta name=\"twitter:site\" content=\"@webcodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Remi Goyard\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"15 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.webcodegeeks.com\/html5\/html5-websocket-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/html5\/html5-websocket-example\/\"},\"author\":{\"name\":\"Remi Goyard\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/ae15332f888fcdc376a8d4e03180e242\"},\"headline\":\"HTML5 websocket example\",\"datePublished\":\"2015-03-26T10:15:38+00:00\",\"dateModified\":\"2017-12-19T12:08:13+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/html5\/html5-websocket-example\/\"},\"wordCount\":2977,\"commentCount\":7,\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/html5\/html5-websocket-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/html5-logo.jpg\",\"keywords\":[\"websocket\"],\"articleSection\":[\"HTML5\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.webcodegeeks.com\/html5\/html5-websocket-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.webcodegeeks.com\/html5\/html5-websocket-example\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/html5\/html5-websocket-example\/\",\"name\":\"HTML5 websocket example - Web Code Geeks - 2026\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/html5\/html5-websocket-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/html5\/html5-websocket-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/html5-logo.jpg\",\"datePublished\":\"2015-03-26T10:15:38+00:00\",\"dateModified\":\"2017-12-19T12:08:13+00:00\",\"description\":\"In this article i will present you the WebSocket feature of HTML5. We will first describe the API, then i'll try to create a small app example using the API.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/html5\/html5-websocket-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.webcodegeeks.com\/html5\/html5-websocket-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/html5\/html5-websocket-example\/#primaryimage\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/html5-logo.jpg\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/html5-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.webcodegeeks.com\/html5\/html5-websocket-example\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.webcodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"HTML5\",\"item\":\"https:\/\/www.webcodegeeks.com\/category\/html5\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"HTML5 websocket example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"name\":\"Web Code Geeks\",\"description\":\"Web Developers Resource Center\",\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.webcodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webcodegeeks\",\"https:\/\/x.com\/webcodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/ae15332f888fcdc376a8d4e03180e242\",\"name\":\"Remi Goyard\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/caa839a88ba9d485eec370ff8e020c314f10fb2e4ddedb3424a4bf92198259b2?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/caa839a88ba9d485eec370ff8e020c314f10fb2e4ddedb3424a4bf92198259b2?s=96&d=mm&r=g\",\"caption\":\"Remi Goyard\"},\"description\":\"I'm a senior web architect. Passionated by new technologies, programming, devops tools, and agile methodologies. I really enjoy to coach, or teach, people who wants to learn programming, from beginners to skilled programmers. Involved in local developer communities, Java User Group, PHP User Group, or Javascript User Group, i like to share with others about experiences, news or business. Coding is FUN !\",\"sameAs\":[\"http:\/\/www.mimiz.fr\/\",\"http:\/\/fr.linkedin.com\/in\/remigoyard\/en\",\"https:\/\/x.com\/@mimiz33\"],\"url\":\"https:\/\/www.webcodegeeks.com\/author\/remi-goyard\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"HTML5 websocket example - Web Code Geeks - 2026","description":"In this article i will present you the WebSocket feature of HTML5. We will first describe the API, then i'll try to create a small app example using the API.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.webcodegeeks.com\/html5\/html5-websocket-example\/","og_locale":"en_US","og_type":"article","og_title":"HTML5 websocket example - Web Code Geeks - 2026","og_description":"In this article i will present you the WebSocket feature of HTML5. We will first describe the API, then i'll try to create a small app example using the API.","og_url":"https:\/\/www.webcodegeeks.com\/html5\/html5-websocket-example\/","og_site_name":"Web Code Geeks","article_publisher":"https:\/\/www.facebook.com\/webcodegeeks","article_published_time":"2015-03-26T10:15:38+00:00","article_modified_time":"2017-12-19T12:08:13+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/html5-logo.jpg","type":"image\/jpeg"}],"author":"Remi Goyard","twitter_card":"summary_large_image","twitter_creator":"@mimiz33","twitter_site":"@webcodegeeks","twitter_misc":{"Written by":"Remi Goyard","Est. reading time":"15 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.webcodegeeks.com\/html5\/html5-websocket-example\/#article","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/html5\/html5-websocket-example\/"},"author":{"name":"Remi Goyard","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/ae15332f888fcdc376a8d4e03180e242"},"headline":"HTML5 websocket example","datePublished":"2015-03-26T10:15:38+00:00","dateModified":"2017-12-19T12:08:13+00:00","mainEntityOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/html5\/html5-websocket-example\/"},"wordCount":2977,"commentCount":7,"publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/html5\/html5-websocket-example\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/html5-logo.jpg","keywords":["websocket"],"articleSection":["HTML5"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.webcodegeeks.com\/html5\/html5-websocket-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.webcodegeeks.com\/html5\/html5-websocket-example\/","url":"https:\/\/www.webcodegeeks.com\/html5\/html5-websocket-example\/","name":"HTML5 websocket example - Web Code Geeks - 2026","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/html5\/html5-websocket-example\/#primaryimage"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/html5\/html5-websocket-example\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/html5-logo.jpg","datePublished":"2015-03-26T10:15:38+00:00","dateModified":"2017-12-19T12:08:13+00:00","description":"In this article i will present you the WebSocket feature of HTML5. We will first describe the API, then i'll try to create a small app example using the API.","breadcrumb":{"@id":"https:\/\/www.webcodegeeks.com\/html5\/html5-websocket-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.webcodegeeks.com\/html5\/html5-websocket-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/html5\/html5-websocket-example\/#primaryimage","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/html5-logo.jpg","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/html5-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.webcodegeeks.com\/html5\/html5-websocket-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.webcodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"HTML5","item":"https:\/\/www.webcodegeeks.com\/category\/html5\/"},{"@type":"ListItem","position":3,"name":"HTML5 websocket example"}]},{"@type":"WebSite","@id":"https:\/\/www.webcodegeeks.com\/#website","url":"https:\/\/www.webcodegeeks.com\/","name":"Web Code Geeks","description":"Web Developers Resource Center","publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.webcodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.webcodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.webcodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webcodegeeks","https:\/\/x.com\/webcodegeeks"]},{"@type":"Person","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/ae15332f888fcdc376a8d4e03180e242","name":"Remi Goyard","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/caa839a88ba9d485eec370ff8e020c314f10fb2e4ddedb3424a4bf92198259b2?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/caa839a88ba9d485eec370ff8e020c314f10fb2e4ddedb3424a4bf92198259b2?s=96&d=mm&r=g","caption":"Remi Goyard"},"description":"I'm a senior web architect. Passionated by new technologies, programming, devops tools, and agile methodologies. I really enjoy to coach, or teach, people who wants to learn programming, from beginners to skilled programmers. Involved in local developer communities, Java User Group, PHP User Group, or Javascript User Group, i like to share with others about experiences, news or business. Coding is FUN !","sameAs":["http:\/\/www.mimiz.fr\/","http:\/\/fr.linkedin.com\/in\/remigoyard\/en","https:\/\/x.com\/@mimiz33"],"url":"https:\/\/www.webcodegeeks.com\/author\/remi-goyard\/"}]}},"_links":{"self":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/2899","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/users\/46"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/comments?post=2899"}],"version-history":[{"count":0,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/2899\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media\/914"}],"wp:attachment":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media?parent=2899"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/categories?post=2899"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/tags?post=2899"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}