Skip to content

Instantly share code, notes, and snippets.

View non-reai's full-sized avatar

Non_Reai non-reai

View GitHub Profile
@non-reai
non-reai / websocket-server.js
Last active March 27, 2023 19:27
Native nodejs websocket server with http module + no libraries
const http = require("http")
const crypto = require("crypto")
const server = http.createServer((req,res)=>{
res.write("hi")
res.end()
})
server.on("upgrade",(req,socket)=>{
const accept = crypto.Hash("sha1").update(req.headers["sec-websocket-key"]+"258EAFA5-E914-47DA-95CA-C5AB0DC85B11").digest("base64")