客户端的 NodeJS api - "net"
NodeJS api - "net" on client side
我想在客户端使用 api - "net"(https://nodejs.org/api/net.html)。
我的代码看起来像:
const net = require('net');
const client = net.connect({port: 8124}, () => {
console.log('connected to server!');
client.write('hello world!');
});
client.on('end', () => {
console.log('disconnected from server');
});
我不想使用 websocket、socketio 或其他库。
关于如何让它工作的任何想法?
非常感谢!
Net
在浏览器上不可用,因为浏览器无法打开任意 TCP 套接字。根据您的情况,探索的选项很少是 net-browserify
或 http-stream
我想在客户端使用 api - "net"(https://nodejs.org/api/net.html)。 我的代码看起来像:
const net = require('net');
const client = net.connect({port: 8124}, () => {
console.log('connected to server!');
client.write('hello world!');
});
client.on('end', () => {
console.log('disconnected from server');
});
我不想使用 websocket、socketio 或其他库。 关于如何让它工作的任何想法?
非常感谢!
Net
在浏览器上不可用,因为浏览器无法打开任意 TCP 套接字。根据您的情况,探索的选项很少是 net-browserify
或 http-stream