6 ms·
My understanding is it's because there's no API for dealing with raw sockets in JS. Or rather, there is, and it's called WebSockets. (Depending on how you want
by wfunction 10y ago
My understanding is it's because there's no API for dealing with raw sockets in JS. Or rather, there is, and it's called WebSockets. (Depending on how you want to look at it...)
- Buge 10y agoWell this thing is written in js, and needs to use raw sockets in its implementation. See "tcpSocket" and "pipe" in the code. Sure browsers don't have a js raw socket API, but no browsers are involved in this thing.
- deleted 10y ago[deleted]
- netgusto 10y agoNope, there is actually a core API for dealing with raw sockets in NodeJS : https://nodejs.org/api/net.html#net_class_net_socket https://nodejs.org/api/net.html#net_class_net_socket Pretty straightforward to use, at that : const net = require('net'); const client = new net.Socket(); client.connect(port, host, function() { client.write("hello !"); });
- deleted 10y ago[deleted]
- wfunction 10y agoInteresting, thanks! So what is the benefit of WebSockets?!
- gbuk2013 10y agoWhat this Node module offers is not raw sockets - let's not spread misinformation. ;) https://en.m.wikipedia.org/wiki/Raw_socket https://en.m.wikipedia.org/wiki/Raw_socket It does not even offer real access to a TCP socket, for example you can't set any options or flags in the TCP header of a packet. All that it provides is a way to open a socket and send / receive data. Very useful, but not a raw socket.
- netgusto 10y agoI stand corrected. Smarter every day they say !
- derhuerst 10y agoyup, the core `socket` module in Node.js is meant for that.
- gbuk2013 10y agoWrong again - the socket module does not give you raw sockets. If you were loo lazy to read the Wikipedia link I suggest you reconsider and educate yourself on the subject.
- derhuerst 10y agoyou're right, i was wrong, there is no core `socket` module (anymore?). but you were not right either. node core can only tell if a file is a socket, but not read from it, at least that's what the docs say. for people interested in this: https://github.com/santigimeno/node-unix-stream https://github.com/santigimeno/node-unix-stream
- gbuk2013 10y agoWrong again. What I said was that there was no native module in Node that would give you _raw socket_ access. And there isn't. Period. The thing you linked to doesn't either. Jeez ... :(