lawlietxxl
V2EX  ›  Node.js

nodejs 如何更灵活的使用 socket 读取的数据 和 使用 socket

  •  
  •   lawlietxxl · Dec 14, 2015 · 4781 views
    This topic created in 3833 days ago, the information mentioned may be changed or developed.

    难道只能在 socket.on("data",function(data){})这样的事件触发回调函数里面才能用吗?

    如果我想写一个服务器,把所有的 socket 都显示的放在数据结构里面,然后进行 read write ,这样如何做?

    1 replies    2015-12-14 13:07:43 +08:00
    foxwoods
        1
    foxwoods  
       Dec 14, 2015
    去 读 [stream 的 API 文档]( https://nodejs.org/api/stream.html)

    > Readable streams have two "modes": a flowing mode and a paused mode.
    > When in flowing mode, data is read from the underlying system and provided to
    > your program as fast as possible. In paused mode, you must explicitly call
    > stream.read() to get chunks of data out. Streams start out in paused mode.

    #RTFM
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3644 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 42ms · UTC 04:36 · PVG 12:36 · LAX 21:36 · JFK 00:36
    ♥ Do have faith in what you're doing.