<story><title>Writing a toy WebSocket server from scratch</title><url>https://alexanderell.is/posts/websockets-from-scratch/</url></story><parent_chain></parent_chain><comment><author>jstanley</author><text>I like writing toy servers too, but I don&amp;#x27;t get a lot of opportunities, so my latest project is a programming challenge that presents a new protocol spec every 2 weeks for people to implement, and automatically tests the implementations[0].&lt;p&gt;OP says:&lt;p&gt;&amp;gt; Goal: write a basic server that can handle the WS handshake and parse an incoming WS frame to see the message sent from the client&lt;p&gt;&amp;gt; Non-goals: writing a robust or real HTTP server, writing a fully compliant WS server, or handling all edge cases&lt;p&gt;This is a great way to get started with something that you don&amp;#x27;t yet understand. I sometimes think of it as implementing &amp;quot;just enough to trick people into thinking that it works&amp;quot;.&lt;p&gt;FWIW, I think the implementation in this post has a bug whereby a client that sends half an HTTP request will block the entire server from accepting further connections, because handle_request() makes blocking calls to recv() until it has a full request, and the program can&amp;#x27;t accept new connections until handle_request() returns. That&amp;#x27;s the spirit!&lt;p&gt;[0] &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;protohackers.com&amp;#x2F;&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;protohackers.com&amp;#x2F;&lt;/a&gt;</text></comment>
<story><title>Writing a toy WebSocket server from scratch</title><url>https://alexanderell.is/posts/websockets-from-scratch/</url></story><parent_chain></parent_chain><comment><author>paxys</author><text>“If you wish to make an apple pie from scratch, you must first invent the universe” – Carl Sagan&lt;p&gt;It&amp;#x27;s interesting to see what different people mean when they say &amp;quot;from scratch&amp;quot;. In this case the lowest abstraction is (what seems to be) Python&amp;#x27;s TCP library.</text></comment>