walter-ws 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +75 -2
- package/bin/walter-ws.js +104 -0
- package/package.json +44 -4
- package/src/client.js +248 -0
- package/src/connection.js +470 -0
- package/src/constants.js +67 -0
- package/src/frame.js +399 -0
- package/src/index.d.ts +148 -0
- package/src/index.js +32 -0
- package/src/index.mjs +23 -0
- package/src/server.js +350 -0
package/README.md
CHANGED
|
@@ -1,3 +1,76 @@
|
|
|
1
|
-
#
|
|
1
|
+
# walter-ws ⚡
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Sıfır dış bağımlılığa sahip (**zero-dependency**), tamamen saf Node.js üzerinde çalışan ultra hızlı **RFC 6455 WebSocket Sunucu & İstemci** kütüphanesi.
|
|
4
|
+
|
|
5
|
+
Standart `ws` paketinin birebir **drop-in** (doğrudan) alternatifidir ve pre-encoded broadcast, 32-bit blok maskeleme ve zero-copy `socket.cork()` mimarisiyle çoklu istemci ve büyük veri transferlerinde yüksek performans sunar.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Kurulum
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
# NPM üzerinden kurulum:
|
|
13
|
+
npm i walter-ws
|
|
14
|
+
|
|
15
|
+
# Veya "walter" takma adıyla (alias) kullanmak için:
|
|
16
|
+
npm i walter@npm:walter-ws
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## Kullanım (CommonJS & ES Modules)
|
|
22
|
+
|
|
23
|
+
### 1. Sunucu Oluşturma
|
|
24
|
+
|
|
25
|
+
```js
|
|
26
|
+
// CommonJS:
|
|
27
|
+
const { WebSocketServer } = require('walter-ws');
|
|
28
|
+
// veya: const { WalterServer } = require('walter-ws');
|
|
29
|
+
// veya ESM: import { WebSocketServer } from 'walter-ws';
|
|
30
|
+
|
|
31
|
+
const wss = new WebSocketServer({
|
|
32
|
+
port: 8080,
|
|
33
|
+
maxPayload: 1024 * 1024, // 1 MB limit
|
|
34
|
+
heartbeatInterval: 30000, // Otomatik ping/pong kontrolü
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
wss.on('connection', (ws, req) => {
|
|
38
|
+
ws.send('Merhaba walter-ws!');
|
|
39
|
+
|
|
40
|
+
ws.on('message', (data, isBinary) => {
|
|
41
|
+
// Gönderen hariç herkese tek seferde pre-encoded yayın (Broadcast)
|
|
42
|
+
wss.broadcast(data, { except: ws, binary: isBinary });
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### 2. İstemci (Client) Kullanımı
|
|
48
|
+
|
|
49
|
+
```js
|
|
50
|
+
const WebSocket = require('walter-ws');
|
|
51
|
+
|
|
52
|
+
const ws = new WebSocket('ws://127.0.0.1:8080');
|
|
53
|
+
|
|
54
|
+
ws.on('open', () => {
|
|
55
|
+
ws.send('Selam sunucu!');
|
|
56
|
+
ws.sendJSON({ event: 'ping', ts: Date.now() });
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
ws.on('message', (data, isBinary) => {
|
|
60
|
+
console.log('Gelen mesaj:', data);
|
|
61
|
+
});
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## CLI (Komut Satırı Aracı)
|
|
67
|
+
|
|
68
|
+
Global kurulduğunda veya `npx` ile doğrudan terminalden WebSocket sunucusu açabilir ya da herhangi bir WebSocket adresine bağlanabilirsiniz:
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
# 8080 portunda hızlı test sunucusu başlatır
|
|
72
|
+
walter server 8080
|
|
73
|
+
|
|
74
|
+
# Bir WebSocket sunucusuna interaktif terminal istemcisiyle bağlanır
|
|
75
|
+
walter connect ws://127.0.0.1:8080
|
|
76
|
+
```
|
package/bin/walter-ws.js
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const readline = require('node:readline');
|
|
5
|
+
const { WalterServer, WalterClient } = require('../src');
|
|
6
|
+
|
|
7
|
+
const args = process.argv.slice(2);
|
|
8
|
+
const command = args[0];
|
|
9
|
+
|
|
10
|
+
function printHelp() {
|
|
11
|
+
console.log(`
|
|
12
|
+
walter-ws — Ultra-Fast Zero-Dependency RFC 6455 WebSocket CLI
|
|
13
|
+
|
|
14
|
+
Kullanım:
|
|
15
|
+
walter-ws server [port] [host] WebSocket Echo & Broadcast sunucusu başlatır (Varsayılan: 8080)
|
|
16
|
+
walter-ws connect <ws://url> Belirtilen WebSocket sunucusuna interaktif bağlanır
|
|
17
|
+
walter-ws --help Bu yardım mesajını gösterir
|
|
18
|
+
|
|
19
|
+
Örnekler:
|
|
20
|
+
walter-ws server 8080
|
|
21
|
+
walter-ws connect ws://127.0.0.1:8080
|
|
22
|
+
`);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (!command || command === '--help' || command === '-h') {
|
|
26
|
+
printHelp();
|
|
27
|
+
process.exit(0);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (command === 'server' || command === 'serve') {
|
|
31
|
+
const port = Number(args[1]) || Number(process.env.PORT) || 8080;
|
|
32
|
+
const host = args[2] || process.env.HOST || '127.0.0.1';
|
|
33
|
+
|
|
34
|
+
const wss = new WalterServer({ port, host, heartbeatInterval: 30000 });
|
|
35
|
+
|
|
36
|
+
wss.on('listening', (addr) => {
|
|
37
|
+
console.log(`[walter-ws] Sunucu dinleniyor: ws://${addr.address}:${addr.port}`);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
wss.on('connection', (ws, req) => {
|
|
41
|
+
console.log(`[+] Bağlantı açıldı (#${ws.id}) - ${req.socket.remoteAddress}`);
|
|
42
|
+
|
|
43
|
+
ws.on('message', (data, isBinary) => {
|
|
44
|
+
console.log(`[#${ws.id}] -> ${isBinary ? `<Binary ${data.length}B>` : data}`);
|
|
45
|
+
ws.send(data, { binary: isBinary });
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
ws.on('close', (code, reason) => {
|
|
49
|
+
console.log(`[-] Bağlantı kapandı (#${ws.id}) [Kod: ${code}${reason ? `, Sebep: ${reason}` : ''}]`);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
} else if (command === 'connect' || command === 'client' || command.startsWith('ws://') || command.startsWith('wss://')) {
|
|
53
|
+
const targetUrl = command.startsWith('ws') ? command : args[1];
|
|
54
|
+
if (!targetUrl) {
|
|
55
|
+
console.error('Hata: Bağlanılacak bir ws:// veya wss:// adresi belirtin.');
|
|
56
|
+
process.exit(1);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const client = new WalterClient(targetUrl);
|
|
60
|
+
|
|
61
|
+
const rl = readline.createInterface({
|
|
62
|
+
input: process.stdin,
|
|
63
|
+
output: process.stdout,
|
|
64
|
+
prompt: 'walter-ws> ',
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
client.on('open', () => {
|
|
68
|
+
console.log(`[walter-ws] Bağlandı: ${targetUrl}`);
|
|
69
|
+
rl.prompt();
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
client.on('message', (data, isBinary) => {
|
|
73
|
+
process.stdout.clearLine?.(0);
|
|
74
|
+
process.stdout.cursorTo?.(0);
|
|
75
|
+
console.log(`< ${isBinary ? `<Binary ${data.length}B>` : data}`);
|
|
76
|
+
rl.prompt();
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
client.on('close', (code, reason) => {
|
|
80
|
+
console.log(`\n[walter-ws] Bağlantı kapandı (Kod: ${code}${reason ? `, Sebep: ${reason}` : ''})`);
|
|
81
|
+
process.exit(0);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
client.on('error', (err) => {
|
|
85
|
+
console.error(`\n[walter-ws] Hata: ${err.message}`);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
rl.on('line', (line) => {
|
|
89
|
+
const trimmed = line.trim();
|
|
90
|
+
if (trimmed === '/quit' || trimmed === '/exit') {
|
|
91
|
+
client.close(1000, 'Client exited');
|
|
92
|
+
rl.close();
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
if (client.readyState === 1 && trimmed.length > 0) {
|
|
96
|
+
client.send(trimmed);
|
|
97
|
+
}
|
|
98
|
+
rl.prompt();
|
|
99
|
+
});
|
|
100
|
+
} else {
|
|
101
|
+
console.error(`Bilinmeyen komut: ${command}`);
|
|
102
|
+
printHelp();
|
|
103
|
+
process.exit(1);
|
|
104
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,46 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "walter-ws",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Ultra-fast zero-dependency RFC 6455 WebSocket Server & Client implementation in pure Node.js",
|
|
5
|
+
"main": "./src/index.js",
|
|
6
|
+
"module": "./src/index.mjs",
|
|
7
|
+
"types": "./src/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./src/index.d.ts",
|
|
11
|
+
"import": "./src/index.mjs",
|
|
12
|
+
"require": "./src/index.js",
|
|
13
|
+
"default": "./src/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"bin": {
|
|
17
|
+
"walter-ws": "bin/walter-ws.js",
|
|
18
|
+
"walter": "bin/walter-ws.js"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"src/",
|
|
22
|
+
"bin/",
|
|
23
|
+
"README.md"
|
|
24
|
+
],
|
|
25
|
+
"scripts": {
|
|
26
|
+
"start": "node examples/server.js",
|
|
27
|
+
"test": "node --test test/walter-ws.test.js",
|
|
28
|
+
"bench": "node benchmark/vs.js"
|
|
29
|
+
},
|
|
30
|
+
"keywords": [
|
|
31
|
+
"websocket",
|
|
32
|
+
"rfc6455",
|
|
33
|
+
"ws",
|
|
34
|
+
"walter",
|
|
35
|
+
"walter-ws",
|
|
36
|
+
"zero-dependency"
|
|
37
|
+
],
|
|
38
|
+
"author": "",
|
|
39
|
+
"license": "MIT",
|
|
40
|
+
"engines": {
|
|
41
|
+
"node": ">=18.0.0"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"ws": "^8.20.0"
|
|
45
|
+
}
|
|
46
|
+
}
|
package/src/client.js
ADDED
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const http = require('node:http');
|
|
4
|
+
const https = require('node:https');
|
|
5
|
+
const crypto = require('node:crypto');
|
|
6
|
+
const { EventEmitter } = require('node:events');
|
|
7
|
+
const { READY_STATES, CLOSE_CODES } = require('./constants');
|
|
8
|
+
const { WalterConnection } = require('./connection');
|
|
9
|
+
const { computeAcceptKey } = require('./server');
|
|
10
|
+
|
|
11
|
+
const KEY_POOL_SIZE = 4096;
|
|
12
|
+
const keyPool = Buffer.allocUnsafe(KEY_POOL_SIZE);
|
|
13
|
+
crypto.randomFillSync(keyPool);
|
|
14
|
+
let keyPoolOffset = 0;
|
|
15
|
+
|
|
16
|
+
function generateSecWebSocketKey() {
|
|
17
|
+
if (keyPoolOffset + 16 > KEY_POOL_SIZE) {
|
|
18
|
+
crypto.randomFillSync(keyPool);
|
|
19
|
+
keyPoolOffset = 0;
|
|
20
|
+
}
|
|
21
|
+
const key = keyPool.subarray(keyPoolOffset, keyPoolOffset + 16).toString('base64');
|
|
22
|
+
keyPoolOffset += 16;
|
|
23
|
+
return key;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Pure Node.js RFC 6455 WebSocket Client ("walter-ws").
|
|
28
|
+
*/
|
|
29
|
+
class WalterClient extends EventEmitter {
|
|
30
|
+
/**
|
|
31
|
+
* @param {string|URL} url - WebSocket URL (ws:// or wss://)
|
|
32
|
+
* @param {object} [options]
|
|
33
|
+
* @param {Record<string, string>} [options.headers] - Custom HTTP headers for the handshake
|
|
34
|
+
* @param {string|string[]} [options.protocols] - Optional subprotocol(s)
|
|
35
|
+
* @param {number} [options.maxPayload=1048576] - Max allowed incoming frame/message payload size in bytes
|
|
36
|
+
* @param {number} [options.handshakeTimeout=10000] - Handshake timeout in ms
|
|
37
|
+
*/
|
|
38
|
+
constructor(url, options = {}) {
|
|
39
|
+
super();
|
|
40
|
+
|
|
41
|
+
this.url = typeof url === 'string' ? new URL(url) : url;
|
|
42
|
+
if (this.url.protocol !== 'ws:' && this.url.protocol !== 'wss:') {
|
|
43
|
+
throw new Error(`Invalid WebSocket URL protocol: ${this.url.protocol}`);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
this.options = {
|
|
47
|
+
headers: options.headers || {},
|
|
48
|
+
protocols: options.protocols || null,
|
|
49
|
+
maxPayload: options.maxPayload ?? 1024 * 1024,
|
|
50
|
+
handshakeTimeout: options.handshakeTimeout ?? 10000,
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
this.readyState = READY_STATES.CONNECTING;
|
|
54
|
+
/** @type {WalterConnection|null} */
|
|
55
|
+
this._connection = null;
|
|
56
|
+
this._req = null;
|
|
57
|
+
|
|
58
|
+
this._connect();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Initiates the HTTP Upgrade handshake with the remote server.
|
|
63
|
+
*/
|
|
64
|
+
_connect() {
|
|
65
|
+
const isSecure = this.url.protocol === 'wss:';
|
|
66
|
+
const transport = isSecure ? https : http;
|
|
67
|
+
const key = generateSecWebSocketKey();
|
|
68
|
+
const expectedAccept = computeAcceptKey(key);
|
|
69
|
+
|
|
70
|
+
const headers = {
|
|
71
|
+
...this.options.headers,
|
|
72
|
+
Upgrade: 'websocket',
|
|
73
|
+
Connection: 'Upgrade',
|
|
74
|
+
'Sec-WebSocket-Key': key,
|
|
75
|
+
'Sec-WebSocket-Version': '13',
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
if (this.options.protocols) {
|
|
79
|
+
const protoList = Array.isArray(this.options.protocols)
|
|
80
|
+
? this.options.protocols.join(', ')
|
|
81
|
+
: String(this.options.protocols);
|
|
82
|
+
headers['Sec-WebSocket-Protocol'] = protoList;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const reqOptions = {
|
|
86
|
+
protocol: isSecure ? 'https:' : 'http:',
|
|
87
|
+
hostname: this.url.hostname,
|
|
88
|
+
port: this.url.port || (isSecure ? 443 : 80),
|
|
89
|
+
path: `${this.url.pathname}${this.url.search}`,
|
|
90
|
+
method: 'GET',
|
|
91
|
+
headers,
|
|
92
|
+
agent: false,
|
|
93
|
+
timeout: this.options.handshakeTimeout,
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const req = transport.request(reqOptions);
|
|
97
|
+
this._req = req;
|
|
98
|
+
|
|
99
|
+
req.on('timeout', () => {
|
|
100
|
+
req.destroy(new Error('WebSocket opening handshake timed out'));
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
req.on('error', (err) => {
|
|
104
|
+
if (this.readyState !== READY_STATES.CLOSED) {
|
|
105
|
+
this.readyState = READY_STATES.CLOSED;
|
|
106
|
+
this.emit('error', err);
|
|
107
|
+
this.emit('close', CLOSE_CODES.ABNORMAL_CLOSURE, err.message);
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
req.on('response', (res) => {
|
|
112
|
+
const err = new Error(`Unexpected server response: ${res.statusCode}`);
|
|
113
|
+
this.readyState = READY_STATES.CLOSED;
|
|
114
|
+
res.resume();
|
|
115
|
+
this.emit('error', err);
|
|
116
|
+
this.emit('close', CLOSE_CODES.ABNORMAL_CLOSURE, err.message);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
req.on('upgrade', (res, socket, head) => {
|
|
120
|
+
const acceptHeader = res.headers['sec-websocket-accept'];
|
|
121
|
+
if (acceptHeader !== expectedAccept) {
|
|
122
|
+
socket.destroy();
|
|
123
|
+
const err = new Error(
|
|
124
|
+
`Invalid Sec-WebSocket-Accept header: expected ${expectedAccept}, got ${acceptHeader}`
|
|
125
|
+
);
|
|
126
|
+
this.readyState = READY_STATES.CLOSED;
|
|
127
|
+
this.emit('error', err);
|
|
128
|
+
this.emit('close', CLOSE_CODES.PROTOCOL_ERROR, err.message);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
this._connection = new WalterConnection(socket, {
|
|
133
|
+
isServer: false, // Client masks outgoing frames and expects unmasked server frames
|
|
134
|
+
maxPayload: this.options.maxPayload,
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
this.readyState = READY_STATES.OPEN;
|
|
138
|
+
this.protocol = res.headers['sec-websocket-protocol'] || null;
|
|
139
|
+
|
|
140
|
+
this._connection.on('message', (data, isBinary) => {
|
|
141
|
+
this.emit('message', data, isBinary);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
this._connection.on('ping', (data) => {
|
|
145
|
+
this.emit('ping', data);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
this._connection.on('pong', (data) => {
|
|
149
|
+
this.emit('pong', data);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
this._connection.on('error', (err) => {
|
|
153
|
+
this.emit('error', err);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
this._connection.on('close', (code, reason) => {
|
|
157
|
+
this.readyState = READY_STATES.CLOSED;
|
|
158
|
+
this.emit('close', code, reason);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
this.emit('open');
|
|
162
|
+
|
|
163
|
+
if (head && head.length > 0) {
|
|
164
|
+
this._connection._onSocketData(head);
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
req.end();
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Sends a text or binary message to the server.
|
|
173
|
+
* @param {string|Buffer|Uint8Array} data
|
|
174
|
+
* @param {object} [options]
|
|
175
|
+
* @param {Function} [callback]
|
|
176
|
+
*/
|
|
177
|
+
send(data, options, callback) {
|
|
178
|
+
if (!this._connection || this.readyState !== READY_STATES.OPEN) {
|
|
179
|
+
throw new Error(`WebSocket is not open: readyState ${this.readyState}`);
|
|
180
|
+
}
|
|
181
|
+
this._connection.send(data, options, callback);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Sends an object serialized as JSON text.
|
|
186
|
+
* @param {any} obj
|
|
187
|
+
* @param {Function} [callback]
|
|
188
|
+
*/
|
|
189
|
+
sendJSON(obj, callback) {
|
|
190
|
+
if (!this._connection || this.readyState !== READY_STATES.OPEN) {
|
|
191
|
+
throw new Error(`WebSocket is not open: readyState ${this.readyState}`);
|
|
192
|
+
}
|
|
193
|
+
this._connection.sendJSON(obj, callback);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Sends a Ping frame to the server.
|
|
198
|
+
* @param {Buffer|string} [data]
|
|
199
|
+
* @param {Function} [callback]
|
|
200
|
+
*/
|
|
201
|
+
ping(data, callback) {
|
|
202
|
+
if (!this._connection || this.readyState !== READY_STATES.OPEN) return;
|
|
203
|
+
this._connection.ping(data, callback);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Sends a Pong frame to the server.
|
|
208
|
+
* @param {Buffer|string} [data]
|
|
209
|
+
* @param {Function} [callback]
|
|
210
|
+
*/
|
|
211
|
+
pong(data, callback) {
|
|
212
|
+
if (!this._connection || this.readyState !== READY_STATES.OPEN) return;
|
|
213
|
+
this._connection.pong(data, callback);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Initiates a clean closing handshake.
|
|
218
|
+
* @param {number} [code=1000]
|
|
219
|
+
* @param {string} [reason='']
|
|
220
|
+
*/
|
|
221
|
+
close(code = CLOSE_CODES.NORMAL_CLOSURE, reason = '') {
|
|
222
|
+
if (this.readyState === READY_STATES.CLOSED || this.readyState === READY_STATES.CLOSING) {
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
this.readyState = READY_STATES.CLOSING;
|
|
226
|
+
if (this._connection) {
|
|
227
|
+
this._connection.close(code, reason);
|
|
228
|
+
} else if (this._req) {
|
|
229
|
+
this._req.destroy();
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Immediately terminates the underlying socket connection.
|
|
235
|
+
*/
|
|
236
|
+
terminate() {
|
|
237
|
+
this.readyState = READY_STATES.CLOSED;
|
|
238
|
+
if (this._connection) {
|
|
239
|
+
this._connection.terminate();
|
|
240
|
+
} else if (this._req) {
|
|
241
|
+
this._req.destroy();
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
module.exports = {
|
|
247
|
+
WalterClient,
|
|
248
|
+
};
|