23 lines
465 B
JavaScript
23 lines
465 B
JavaScript
import * as net from 'net';
|
|
|
|
const hostname = '192.168.1.219';
|
|
const port = 29999;
|
|
|
|
function getBinarySize(string) {
|
|
return Buffer.byteLength(string, 'utf8');
|
|
}
|
|
|
|
export default function req(data, callback, errorCallback) {
|
|
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);
|
|
}
|
|
});
|
|
}
|