I have a websocket server running on the backend using the ws nodejs library. I'm getting this error whenever I am trying to connect to it from the client side.
events.js:377
throw er; // Unhandled 'error' event
^
Error: write EPROTO 4455222784:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:../deps/openssl/openssl/ssl/record/ssl3_record.c:332:
at WriteWrap.onWriteComplete [as oncomplete] (internal/stream_base_commons.js:94:16)
Emitted 'error' event on WebSocket instance at:
at ClientRequest.<anonymous> (/Volumes/lilac/Projects/Projects/5. Fireplace/fireplace/node_modules/ws/lib/websocket.js:718:15)
at ClientRequest.emit (events.js:400:28)
at TLSSocket.socketErrorListener (_http_client.js:475:9)
at TLSSocket.emit (events.js:400:28)
at emitErrorNT (internal/streams/destroy.js:106:8)
at emitErrorCloseNT (internal/streams/destroy.js:74:3)
at processTicksAndRejections (internal/process/task_queues.js:82:21) {
errno: -100,
code: 'EPROTO',
syscall: 'write'
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! fireplace@0.1.0 dev: `next dev`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the fireplace@0.1.0 dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/debabrata/.npm/_logs/2021-08-04T07_56_05_447Z-debug.log
Here's the code running on the server:
import { createServer } from "http"
import { WebSocketServer } from "ws"
const server = createServer()
const wss = new WebSocketServer({ server })
server.listen("8080", () => {
console.log("Server listening on port 8080")
})
wss.on("connection", (ws, req) => {
ws.on("open", () => console.log("connection open"))
ws.on("close", () => console.log("connection closed"))
})
Client side code (Next.js)
import WebSocket from 'isomorphic-ws'
import {useEffect} from 'react'
const ws = new WebSocket("wss://localhost:8080/")
const Page = () => {
useEffect(() => {
ws.onopen = () => {
console.log("connection open")
}
})
return (
<div>
</div>
)
}
export default Page
I should also mention that I had to update npm and node versions while building this. Is that causing a problem? How do I resolve this issue?