net#NetConnectOpts TypeScript Examples
The following examples show how to use
net#NetConnectOpts.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: minecraft.ts From scraper with GNU General Public License v3.0 | 6 votes |
connect (opts?: NetConnectOpts) {
this.socket = net.createConnection({
host: this.ip,
port: this.port,
timeout: this.opts.timeout,
...opts
})
this.socket.on('data', (data) => {
this.response = Buffer.concat([this.response, data])
this.emit('data', data, this.response)
})
this.socket.on('connect', () => {
this.emit('connect')
})
this.socket.on('close', () => {
// this.reject(new ScraperError('Connection closed'));
this.emit('close')
})
this.socket.on('error', () => {
this.reject(new ScraperError('Connection error'))
this.emit('error')
})
this.socket.on('timeout', () => {
this.reject(new ScraperError('Connection timeout'))
this.emit('timeout')
})
}
Example #2
Source File: clientRequestManager.ts From flood with GNU General Public License v3.0 | 6 votes |
sendMethodCall = (methodName: string, parameters: MethodCallParameters) => {
const connectionOptions: NetConnectOpts =
this.connectionSettings.type === 'socket'
? {
path: this.connectionSettings.socket,
}
: {
host: this.connectionSettings.host,
port: this.connectionSettings.port,
};
const methodCall = this.isJSONCapable
? methodCallJSON(connectionOptions, methodName, parameters)
: methodCallXML(connectionOptions, methodName, parameters);
return methodCall.then(
(response) => {
this.handleRequestEnd();
return response;
},
(error) => {
this.handleRequestEnd();
throw error;
},
);
};
Example #3
Source File: proxy.ts From l2js-client with MIT License | 5 votes |
proxy = (cfg: ProxyConfig) => {
const server = createServer(client => {
const connectOption: NetConnectOpts = {
port: cfg.remotePort,
host: cfg.remoteIp
};
// Proxy client
const remote: Socket = connect(connectOption);
client.on("end", () => remote.destroy());
client.on("error", () => remote.destroy());
client.on("data", (data: Uint8Array) => {
client.pause();
remote.write(data);
client.resume();
});
remote.on("data", (data: Uint8Array) => {
remote.pause();
cfg.mmoClient
.process(data)
.then((packet: ReceivablePacket) => {
if (packet != null && packet instanceof ServerList) {
const list = (cfg.mmoClient as LoginClient).Servers;
const fakeServerListPacket = new (class extends SendablePacket {
write(): void {
this.writeC(0x04);
this.writeC(list.length);
this.writeC(1);
list.forEach(s => {
this.writeC(s.Id);
this.writeD(0x0100007f); // 127.0.0.1
this.writeD(s.Port);
this.writeC(s.AgeLimit);
this.writeC(s.Pvp);
this.writeH(s.CurrentPlayers);
this.writeH(s.MaxPlayers);
this.writeC(s.Status);
this.writeD(s.ServerType);
this.writeC(s.Brackets);
});
this.writeH(0);
this.writeC(0);
}
})();
// fakeServerListPacket.Client = cfg.mmoClient as LoginClient;
data = cfg.mmoClient.pack(fakeServerListPacket);
}
client.write(data);
remote.resume();
})
.catch(() => {
client.write(data);
remote.resume();
});
});
remote.on("end", () => client.destroy());
remote.on("error", () => client.destroy());
});
server.listen(cfg.listenPort, () => {
console.info("Listen on port:", cfg.listenPort);
});
}