• Bootcamp (9)
    • 📱 236 - 992 - 3846

      đź“§ jxjwilliam@gmail.com

    • Version: ‍🚀 1.1.0
  • Socket

    BootcampBackend2020-12-17


    Socket.IO

    • cross browser (including IE6)
    • Real-time and bi-directional persistent connection (WebSocket)
    • Wworking for https and cross-domain (if use webSocket or JSONP)
    • Authentication . Cookie & Session . Cookie does not cross domain, use SSL + Access Token instead
    • Use Nginx for loading Balancing.
    • Configurations . Store(default: memoryStore, single process only) . transports(default: websocket, htmlfile, xhr-polling, jsonp-polling) . authorization (default: false)
    • Socket.IO primarily use WebSocket, but can fallback to other methods lik AJAX Long polling, JSONP polling In addition to 1-to-1 communication as in WebSocket, it enables broadcasting to multiple nodes

    modules

    • Redis
    • Socket.io
    • isomorphic-fetch
    • node-jsonwebtoken

    Q&A

    • Pub/Sub or Message Queue

    Processing flow

    1. in browser, when React Component is rendered, in componentDidMount fires a socket.emit,
    2. in server, socket.on is triggered and does redis publish
    3. in server, redis.on does redis-stuff (hgetall…)
    4. in server, redis.on fires socket.emit() to pass/broadcast data to browser.
    5. in browser, socket.on is triggered to process the data, and render the components.

    Reference

    • Forever Iframe
    • XMLHttpRequest Long Polling
    • Cometed
    • Websocket