노마드코더 - 줌 클론코딩 1

Song·2021년 9월 22일
0

Node.js

목록 보기
6/7

[영어주의] 진짜 나 혼자만의 공부 노트,,

기술 스택

  • Express, Pug, Babel

HTTP vs WebSocket (wss)

  • both are protocol

Http

  • request, response
    only when client requests, server can response

  • stateless
    only have connection during request and response
    after while backend forgets about users

  • sum
    no realtime

Websocket

  • realtime chat, notification realtime connection
    seperate from http, a whole different protocol.

  • developer needs to follow rules in order to implement them into codes

  • request comes from client and server can either accpet or deny.

  • After accpeting, connection get established and
    as long as they are 'connected' they can send msg to each other anytime!

  • Browser has a built-in webSocket API

  • Frontend has been already prepared for web socket client so no installation required. It supports the connection with backend on browser

Socket

  • sockect is a certain connection with browser and it contains its own method such as Connection, Send and Close
  • It provides client information through 'on' method, which receives event and funtion which waits for the event to happen

Object → String

When parsing messages using socket method to backend from frontend, the data type shouldn’t be a javascript object as backend server may not be able to read js object if it is go or java server. Therefore, it should send convert the data as string and let backend decide how it wants to manipulate it

JSON.stringify -> JSON.parse
profile
Learn From Yesterday, Live Today, Hope for Tomorrow

0개의 댓글