<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Daniel Lukonis</title>
    <description>The latest articles on DEV Community by Daniel Lukonis (@daniellukonis).</description>
    <link>https://dev.to/daniellukonis</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1012593%2F6c4043ba-fd76-4a29-8703-6238a23bea75.png</url>
      <title>DEV Community: Daniel Lukonis</title>
      <link>https://dev.to/daniellukonis</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/daniellukonis"/>
    <language>en</language>
    <item>
      <title>Super small socket.io</title>
      <dc:creator>Daniel Lukonis</dc:creator>
      <pubDate>Sun, 22 Jan 2023 04:30:49 +0000</pubDate>
      <link>https://dev.to/daniellukonis/super-small-socketio-33p8</link>
      <guid>https://dev.to/daniellukonis/super-small-socketio-33p8</guid>
      <description>&lt;p&gt;Hey friends!&lt;/p&gt;

&lt;p&gt;I looked far and wide on the web to find a very minimal socket.io implementation. No express, no node http module, just socket.io. I couldn't find a suitable example so I wrote one. I plan on using a version of this on my upcoming MMORPG 2D space sim. Link to the repo here: &lt;a href="https://github.com/daniellukonis/minsocketio" rel="noopener noreferrer"&gt;minsocketio&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;Clone the repo:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git clone git@github.com:daniellukonis/minsocketio.git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Install the dependencies with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;then start both the server and client with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;&lt;strong&gt;io.server.js&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const io = require("socket.io")(13555)
  .on("connection", (socket) =&amp;gt; {
    socket.on("data", data =&amp;gt; io.emit("newData", data))
  })
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This creates the socket.io server and listens on port 13555. All it does right now is listens for connected clients to send a message labeled data, and rebroadcasts it to all connected clients.&lt;/p&gt;




&lt;p&gt;io.client.mjs&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { io } from "socket.io-client"
const socket = io("ws://localhost:13555")
socket.on("newData", newData =&amp;gt; console.log(newData))

setInterval(data, 1000)
function data() {
  const d = Math.random()
  socket.emit("data", d)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This client simply connected to the socket.io server and sends a random number. It listens for the server to broadcast a message labeled newData, then logs it to the console.&lt;/p&gt;




&lt;p&gt;Thanks for reading! Keep your ears open for progress on my game. I expect to stream some updates soon!&lt;/p&gt;

&lt;p&gt;Thanks,&lt;br&gt;
Daniel&lt;/p&gt;

</description>
      <category>gratitude</category>
    </item>
  </channel>
</rss>
