<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Joseph Lozano on Medium]]></title>
        <description><![CDATA[Stories by Joseph Lozano on Medium]]></description>
        <link>https://medium.com/@joseph_lozano_?source=rss-d14c6b1e7117------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*_-NTtGJQ9mWgmWPHOYZpQQ.jpeg</url>
            <title>Stories by Joseph Lozano on Medium</title>
            <link>https://medium.com/@joseph_lozano_?source=rss-d14c6b1e7117------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 13:08:38 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@joseph_lozano_/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Building a Simple Chat App with socket.io]]></title>
            <link>https://medium.com/@joseph_lozano_/building-a-simple-chat-app-with-socket-io-e6a8d9d21ae4?source=rss-d14c6b1e7117------2</link>
            <guid isPermaLink="false">https://medium.com/p/e6a8d9d21ae4</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[socketio]]></category>
            <dc:creator><![CDATA[Joseph Lozano]]></dc:creator>
            <pubDate>Tue, 29 Sep 2015 15:01:43 GMT</pubDate>
            <atom:updated>2015-09-29T15:01:43.470Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Building a Simple Chat App with </strong><a href="http://socket.io/"><strong>socket.io</strong></a></p><p><a href="http://socket.io/">socket.io</a> is a javascript library used to enable realtime time communication between browsers.</p><p>Normally browsers communicate with a web server (and through a web server other browsers) in discreet events, such as an Ajax call. With <a href="http://socket.io/">socket.io</a>, you can send and receive messages in real time without needing to make special Ajax calls.</p><p>The first step to learning <a href="http://socket.io/">socket.io</a> is to visit <a href="http://socket.io/">socket.io</a> and checkout their getting started guide. You can find it <a href="http://socket.io/get-started/chat/">here</a>. Following this guide will get you set up with a basic app that can send and receive messages. Few problems: 1) If you try to deploy it to heroic it won’t work. 2) You may have no idea how it works/unfamiliar syntax. 3). The app has very limited functionality.</p><p>Lets start by getting it up on heroku. When I was first trying to get it up, I was reading lots of out of date blog posts saying that heroku didn’t support websockets, and you had use xhr-polling. Fortunately, those posts are out of date, heroku does support web sockets and I don’t have to go into xhr-polling. Getting the app heroku-ready can be done in 3 easy steps. First, change the script where you load jQuery (in your index.html) to load over https instead of http. Second, you have to define the start script. This is the script that heroku will run once you upload it. In your ‘package.json’ file, add and entry that reads</p><pre>“scripts”: {<br> “start”: “node index.js”<br>},</pre><p>What this does is define the script that will run if you type `npm start` into the console. If you forget to the do this, you can see in your heroku logs:</p><pre>npm ERR! missing script: start</pre><p>Finally, you have to let heroku choose what port the server will run on. At the bottom of index.js, you will see a line that looks like</p><pre>http.listen(3000, function(){<br> console.log(‘listening on *:3000’);<br>});</pre><p>3000 is the port defined in the app, but this may not be the one heroku wants to run the app on. Change these lines so they loook like:</p><pre>var port = process.env.PORT || 3000<br>http.listen(port, function(){<br> console.log(‘listening on *:&#39;, port);<br>});</pre><p>Congratulations, your app is now heroku-ready. You can now deploy the app right to heroku. Follow their <a href="https://devcenter.heroku.com/articles/getting-started-with-nodejs#introduction">getting started guide</a> if you don’t know how.</p><p>Now its time to go over what exactly is going on in our app. Firstly, their are 2 parts: The client, and the server. A simple way of thinking about it is that the server runs index.js, while the client runs index.html. Lets start with the server, index.js. There are 4 parts to this file, first defining variables, and loading dependencies. These includes express.js, and socket.io. Second is the routing. What this says is that when a browser visits the web page, send them the index.html file.</p><p>Next time we’ll check out what exactly is going on in the io.on block.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e6a8d9d21ae4" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>