-
Notifications
You must be signed in to change notification settings - Fork 0
/
sendingText.ts
31 lines (24 loc) · 1.1 KB
/
sendingText.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { VBANServer, VBANTEXTPacket, EFormatBit, ETextEncoding } from '../src';
const server = new VBANServer();
server.on('error', (err) => {
console.log(`server error:\n${err.stack}`);
server.close();
});
server.on('listening', () => {
const address = server.address();
console.log(`server listening ${address.address}:${address.port}`);
// when server start, send a message
//We will send a text message each time we receive a packet (for example)
//try to create a new TEXT packet
const textPacket = new VBANTEXTPacket(
{
streamName: 'Command1', //the streamName waited by the other tool
formatBit: EFormatBit.VBAN_DATATYPE_BYTE8, //the storage format, currently this is the only option available
encoding: ETextEncoding.VBAN_TXT_UTF8 //we will send it in UTF8, most of VM Tools use UTF8
},
'test' // => the message we want to send (always in UTF8, if streamType is not UTF8, the library will convert)
);
//send it to 127.0.0.1 on port 6980
server.send(textPacket, 6980, '127.0.0.1');
});
server.bind(7000);