Repository navigation
How to open exist tty using net.Socket ? #37780
Description
Activity
I don't think opening a socket to a TTY fd is supported yet.
At the bottom of https://nodejs.org/api/net.html#net_class_net_socket:The newly created socket can be either a TCP socket or a streaming IPC endpoint, depending on what it connect() to.
@RaisinTen No, it is supported. I think this might also qualify as a bug in the net module.
In any case, one can use
tty.ReadStream(fd)andtty.WriteStream(fd)to create TTY streams (which should be one class but for some reason isn’t), and both of these inherit fromnet.Socket.@addaleax The passed fd type gets rejected here:
. So, this can be fixed by adding an option to accept TTY fds. Should we move this issue to the main repo?Lines 140 to 156 in 3bba40a
function createHandle(fd, is_server) { validateInt32(fd, 'fd', 0); const type = guessHandleType(fd); if (type === 'PIPE') { return new Pipe( is_server ? PipeConstants.SERVER : PipeConstants.SOCKET ); } if (type === 'TCP') { return new TCP( is_server ? TCPConstants.SERVER : TCPConstants.SOCKET ); } throw new ERR_INVALID_FD_TYPE(type); } Yeah, although I think there might also be another issue somewhere for merging the two TTY classes? I think that would be the best solution here.
Thank you, @addaleax and @RaisinTen !
I understand that net.Socket is not supported for tty fd, and I should use tty module instead of net.Socket.So, there is no document about accepting fd in tty modules.
https://nodejs.org/api/tty.html#tty_class_tty_readstreamit is missing? or experimental function?
I don’t know why the constructors are not documented, but they should be, yes.
- addeddocIssues and PRs related to Node.js documentation.Issues and PRs related to Node.js documentation.ttyIssues and PRs related to the tty subsystem.Issues and PRs related to the tty subsystem.
on Mar 31, 2021 - added a commit that references this issue
on Apr 1, 2021 - added a commit that references this issue
on Mar 18, 2024 - added a commit that references this issue
on Jul 19, 2024 - added a commit that references this issue
on Jul 28, 2024 - added a commit that references this issue
on Nov 13, 2024 - added a commit that references this issue
on Feb 25, 2025 - added a commit that references this issue
on Apr 21, 2025
Hi, there
I want to open exist tty using net.Socket. But I got an error like a below.
I have two questions.
First, how can I open tty using net.Socket module ?
Second, I success to open tty using tty.ReadStream like a them. But I didn't find it in document. It is trial function? (It is not safe to use in production?)
thank you