sitegui / nodejs-websocket

A node.js module for websocket server and client
MIT License
736 stars 155 forks source link

undocumented net.Socket `readable` event and `read` method? #37

Closed complyue closed 8 years ago

complyue commented 8 years ago

Hi,

Great work here!

And I'm just curious when read somewhere in your src that like:

    socket.on('readable', function () {
        that.doRead()
    })
...
Connection.prototype.doRead = function () {
    var buffer, temp

    // Fetches the data
    buffer = this.socket.read()
...

But I digged NodeJS api docs up to 0.10, there's no such event as readable and method as read documented. I'm curious whether they are legacies or just undocumented artifacts.

Don't know if its proper to ask the question as an issue, you're free to close it.

Regards & thanks, Compl

sitegui commented 8 years ago

Hi @complyue

It's arguably hard to find in the docs, but net.Socket extends stream.Duplex, that extends both stream.Writable and stream.Readable. Both 'readable' event and read() method are defined (and documented) in the readable stream.

This object is an abstraction of a TCP or local socket. net.Socket instances implement a duplex Stream interface. https://nodejs.org/api/net.html#net_class_net_socket

That's more of a Node.js question, help forums (like https://github.com/nodejs/help) are more suitable for this kind of issue ;)

complyue commented 8 years ago

@sitegui Thanks very much for the direction.