V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
lawlietxxl
V2EX  ›  Node.js

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

  •  
  •   lawlietxxl · 2015-12-14 10:06:45 +08:00 · 3882 次点击
    这是一个创建于 3054 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

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

    1 条回复    2015-12-14 13:07:43 +08:00
    foxwoods
        1
    foxwoods  
       2015-12-14 13:07:43 +08:00
    去 读 [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
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3309 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 11:46 · PVG 19:46 · LAX 04:46 · JFK 07:46
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.