반응형

 

WS

https://www.npmjs.com/package/ws

 

ws

Simple to use, blazing fast and thoroughly tested websocket client and server for Node.js

www.npmjs.com

 

라이브러리 설치

npm i ws

 

websocket과 http 동시에 연결하기

import http from 'http';
import WebSocket from 'ws';

const handleListen = () => console.log("Listening on http://localhost:3000");

const server = http.createServer(app)
const wss = new WebSocket.Server({server})

server.listen(3000, handleListen)

 

http 위에 wss 를 만들어서 같은 포트로 서버를 연결하는 것이다

wss://localhost:3000
http://localhost:3000

위와 같은 방식이 된 것이다.

 

 

 

 

 

반응형
복사했습니다!