JavaScript 4

[JavaScript] WebSocket vs Socket IO

Socket IO ์‹ค์‹œ๊ฐ„, ์–‘๋ฐฉํ–ฅ, event ๊ธฐ๋ฐ˜์˜ ํ†ต์‹ ์„ ํ•˜๋Š” framework webSocket์€ ์œ„์˜ ํ†ต์‹ ์„ ์ œ๊ณตํ•˜๋Š” ์—ฌ๋Ÿฌ ๋ฐฉ๋ฒ• ์ค‘ ํ•˜๋‚˜ Socket IO๋Š” webSocket์˜ ๋ถ€๊ฐ€๊ธฐ๋Šฅ (X) Socket IO๋Š” ๊ฐ€๋” webSocket์„ ์ด์šฉ (O) ๋งŒ์•ฝ webSocket ์ด์šฉ์ด ๋ถˆ๊ฐ€๋Šฅํ•˜๋ฉด, Socket IO๋Š” ๋‹ค๋ฅธ ๋ฐฉ๋ฒ•์„ ์ด์šฉํ•ด์„œ ๊ณ„์† ์ž‘๋™ ์ž๋™ ์žฌ์—ฐ๊ฒฐ ์ง€์›, ์—ฐ๊ฒฐ ๋Š๊น€ ํ™•์ธ, ๋ฐ”์ด๋„ˆ๋ฆฌ ์ง€์› ํƒ„๋ ฅ์„ฑ, ์‹ ๋ขฐ์„ฑ 1. get socket server WebSocket //server.js const httpServer = http.createServer(app); const wsServer = new ws. WebSocketServer({httpServer}); Socket IO ์œ ์ €์—๊ฒŒ URL ์ œ๊ณต..

JavaScript 2024.03.29

[JavaScript] WebSocket | ์„œ๋ฒ„์™€ ๋ธŒ๋ผ์šฐ์ € ์—ฐ๊ฒฐ

1. express ๋กœ ์„œ๋ฒ„ ๊ตฌ์ถ• express ? node.js์˜ ํ”„๋ ˆ์ž„์›Œํฌ ์„œ๋ฒ„ ์‚ฌ์ด๋“œ ํ”„๋ ˆ์ž„์›Œํฌ๋กœ Node.js์˜ API๋ฅผ ๋‹จ์ˆœํ™”ํ•˜๊ณ , ์‰ฝ๊ฒŒ ์„œ๋ฒ„ ๊ตฌ์ถ• ๊ฐ€๋Šฅ express application์œผ๋กœ๋ถ€ํ„ฐ http server ์ƒ์„ฑ import express from 'express'; import http from 'http'; const app = express(); const server = http.createServer(app); 2. http ์„œ๋ฒ„ ์œ„์—, webSocket ์„œ๋ฒ„ ๊ตฌ์ถ• -> ๊ฐ™์€ ํฌํŠธ ์ด์šฉ import ws from 'ws'; //http ์„œ๋ฒ„ ์ „๋‹ฌ const wss = new we.WebSocketServer({ server }); 3. WebSocket Connection :..

JavaScript 2024.03.28

[JavaScript] NodeJS, nodemon, babel | ํ”„๋กœ์ ํŠธ Server Setup

1. ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ -> VSCode ๋กœ ์‹คํ–‰ $ mkdir prjname $ cd prjname $ npm init -y $ code . 2. git ์„ค์ • $ git init . $ git remote add origin gitURL $ git push -u origin main 3. ๊ธฐ๋ณธ ํŒŒ์ผ ์ƒ์„ฑ $ touch README.md $ touch .gitignore 4. nodemon ์„ค์ • $ npm i nodemon -D // nodemon.json { "exec" : "babel-node src/server.js" } 5. babel ์„ค์ • $ npm i @babel/core @babel/cli @babel/node @babel/preset-env -D { "presets" : ["@babel/pre..

JavaScript 2024.03.27