Published 2021. 10. 31. 23:14
반응형
WS
https://www.npmjs.com/package/ws
라이브러리 설치
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
위와 같은 방식이 된 것이다.
반응형
'Backend 언어 및 프레임워크 > Javascript- Node, express, Nest' 카테고리의 다른 글
javascript) 한국 숫자단위 3자리 마다 끊기( 3자리마다 쉼표) (0) | 2022.01.19 |
---|---|
javascript) 여러개(복수) 동시 replace 정규식 이용 (0) | 2022.01.04 |
webSocket 과 http의 차이 (0) | 2021.10.31 |
TypeScript(타입스크립트) 셋팅, 함수,tsc-watch,interface,class 정리 (0) | 2021.10.03 |
타입스크립트 셋팅(set-up) (0) | 2021.09.29 |