network stuff?

This commit is contained in:
jane 2020-11-08 23:15:14 -05:00
parent 6c7bbc2304
commit 2a6f2d6f9b
3 changed files with 42 additions and 16 deletions

View file

@ -1,18 +1,22 @@
import * as https from 'https';
import * as net from 'net';
const options = {
hostname: '192.168.1.219',
port: '29999',
path: '/',
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
};
const hostname = '192.168.1.219';
const port = 29999;
function getBinarySize(string) {
return Buffer.byteLength(string, 'utf8');
}
export default function req(data, callback, errorCallback) {
const request = https.request(options, (res) => callback(res));
request.on('error', (error) => errorCallback(error));
request.write(JSON.stringify(data));
request.end();
let string_data = JSON.stringify(data);
let size = getBinarySize(string_data);
let client = new net.Socket();
client.connect(port, hostname, () => {
let res = client.write(size);
if (res) {
client.write(string_data);
}
});
}

View file

@ -1,12 +1,12 @@
{
"type": "module",
"dependencies": {
"eris": "^0.14.0"
"eris": "^0.14.0",
"socket.engine": "^1.0.0"
},
"name": "lights",
"version": "1.0.0",
"main": "bot.js",
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node bot.js"

View file

@ -1,5 +1,6 @@
dependencies:
eris: 0.14.0
socket.engine: 1.0.0
lockfileVersion: 5.1
packages:
/eris/0.14.0:
@ -13,11 +14,31 @@ packages:
tweetnacl: 1.0.3
resolution:
integrity: sha512-/W6X0SFR2swtA9oc4ga5Wh1TQcZtPgbUaDDdwYc67fvFUAtwC+V1xzWUZq2yDeJnTfB8Uot9SJWA8Lthe2sDtQ==
/fs/0.0.1-security:
dev: false
resolution:
integrity: sha1-invTcYa23d84E/I4WLV+yq9eQdQ=
/ip/1.1.5:
dev: false
resolution:
integrity: sha1-vd7XARQpCCjAoDnnLvJfWq7ENUo=
/net/1.0.2:
dev: false
resolution:
integrity: sha1-0XV+yaf7I3HYPPR1XOPifhCCk4g=
/opusscript/0.0.7:
dev: false
optional: true
resolution:
integrity: sha512-DcBadTdYTUuH9zQtepsLjQn4Ll6rs3dmeFvN+SD0ThPnxRBRm/WC1zXWPg+wgAJimB784gdZvUMA57gDP7FdVg==
/socket.engine/1.0.0:
dependencies:
fs: 0.0.1-security
ip: 1.1.5
net: 1.0.2
dev: false
resolution:
integrity: sha512-vwc9JVBNe33686TBl9T3Ro53FaF09z11NVnrf0HIlYUOIDaZ1OFA1J1O6igU57qhP3NyUv4a+kZtgMm6SnziaQ==
/tweetnacl/1.0.3:
dev: false
optional: true
@ -39,3 +60,4 @@ packages:
integrity: sha512-D3RuNkynyHmEJIpD2qrgVkc9DQ23OrN/moAwZX4L8DfvszsJxpjQuUq3LMx6HoYji9fbIOBY18XWBsAux1ZZUA==
specifiers:
eris: ^0.14.0
socket.engine: ^1.0.0