-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.js
More file actions
executable file
·51 lines (40 loc) · 1.24 KB
/
Copy pathclient.js
File metadata and controls
executable file
·51 lines (40 loc) · 1.24 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/gjs --include-path=.
'use strict';
imports.searchPath.unshift('.');
const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
const Utils = imports.utils;
let socket_address = Utils.new_socket_address();
/**
* Send a request to the server.
* @param {String} request
*/
function makeRequest(request)
{
try {
// start a new client
let client = new Gio.SocketClient();
let connection = client.connect(socket_address, null);
if (!connection) {
throw "Connection failed"
}
// get the input and output streams
let input = connection.get_input_stream();
let output = connection.get_output_stream();
// write the signal as a string to the output stream
output.write_bytes(new GLib.Bytes(''+request), null);
// get the response from the input stream as a string
let response = String.fromCharCode.apply(null, input.read_bytes(Utils.NUM_BYTES, null).get_data());
print('Requested '+request+'. received response: '+response);
connection.close(null);
} catch (err) {
print(err);
return false;
}
return true;
}
makeRequest(1) &&
makeRequest(2) &&
makeRequest(3) &&
makeRequest(4) &&
makeRequest(9);