TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Writing a toy WebSocket server from scratch

157 pointsby otrasover 2 years ago

5 comments

jstanleyover 2 years ago
I like writing toy servers too, but I don&#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].<p>OP says:<p>&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<p>&gt; Non-goals: writing a robust or real HTTP server, writing a fully compliant WS server, or handling all edge cases<p>This is a great way to get started with something that you don&#x27;t yet understand. I sometimes think of it as implementing &quot;just enough to trick people into thinking that it works&quot;.<p>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&#x27;t accept new connections until handle_request() returns. That&#x27;s the spirit!<p>[0] <a href="https:&#x2F;&#x2F;protohackers.com&#x2F;" rel="nofollow">https:&#x2F;&#x2F;protohackers.com&#x2F;</a>
评论 #32655924 未加载
评论 #32660788 未加载
评论 #32660076 未加载
评论 #32656062 未加载
paxysover 2 years ago
“If you wish to make an apple pie from scratch, you must first invent the universe” – Carl Sagan<p>It&#x27;s interesting to see what different people mean when they say &quot;from scratch&quot;. In this case the lowest abstraction is (what seems to be) Python&#x27;s TCP library.
评论 #32657353 未加载
评论 #32658965 未加载
评论 #32656509 未加载
ok_dadover 2 years ago
I love this article! I&#x27;m going to start my own series of &quot;toys&quot; for my personal edification now, I never thought doing something half-assed would be so much fun! I mean that with the utmost of respect, too, because I have been stressing so much lately trying to build something &quot;commercializable&quot; but I should have been focusing on educating myself and having fun with tiny projects like this, which can be completed in a few days.
评论 #32655370 未加载
lobotaover 2 years ago
Love this article, i was working on a project for an inverse.proxy with CORS + websockets, spent few weeks learning deep HTTP and ws. Is a good experience to learn the basic building blocks of tech
convolvatronover 2 years ago
some peers...I think Chrome...will shut down your connection if you don&#x27;t have a WS layer keep alive