本文整理汇总了TypeScript中smart-buffer.SmartBuffer.writeBuffer方法的典型用法代码示例。如果您正苦于以下问题:TypeScript SmartBuffer.writeBuffer方法的具体用法?TypeScript SmartBuffer.writeBuffer怎么用?TypeScript SmartBuffer.writeBuffer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类smart-buffer.SmartBuffer
的用法示例。
在下文中一共展示了SmartBuffer.writeBuffer方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: sendSocks5CommandRequest
/**
* Sends Socks v5 final handshake request.
*/
private sendSocks5CommandRequest() {
const buff = new SmartBuffer();
buff.writeUInt8(0x05);
buff.writeUInt8(SocksCommand[this._options.command]);
buff.writeUInt8(0x00);
// ipv4, ipv6, domain?
if (net.isIPv4(this._options.destination.host)) {
buff.writeUInt8(Socks5HostType.IPv4);
buff.writeBuffer(ip.toBuffer(this._options.destination.host));
} else if (net.isIPv6(this._options.destination.host)) {
buff.writeUInt8(Socks5HostType.IPv6);
buff.writeBuffer(ip.toBuffer(this._options.destination.host));
} else {
buff.writeUInt8(Socks5HostType.Hostname);
buff.writeUInt8(this._options.destination.host.length);
buff.writeString(this._options.destination.host);
}
buff.writeUInt16BE(this._options.destination.port);
this._nextRequiredPacketBufferSize =
SOCKS_INCOMING_PACKET_SIZES.Socks5ResponseHeader;
this._socket.write(buff.toBuffer());
this.state = SocksClientState.SentFinalHandshake;
}
示例2: createUDPFrame
/**
* Creates a SOCKS UDP Frame.
* @param options
*/
static createUDPFrame(options: SocksUDPFrameDetails): Buffer {
const buff = new SmartBuffer();
buff.writeUInt16BE(0);
buff.writeUInt8(options.frameNumber || 0);
// IPv4/IPv6/Hostname
if (net.isIPv4(options.remoteHost.host)) {
buff.writeUInt8(Socks5HostType.IPv4);
buff.writeUInt32BE(ip.toLong(options.remoteHost.host));
} else if (net.isIPv6(options.remoteHost.host)) {
buff.writeUInt8(Socks5HostType.IPv6);
buff.writeBuffer(ip.toBuffer(options.remoteHost.host));
} else {
buff.writeUInt8(Socks5HostType.Hostname);
buff.writeUInt8(Buffer.byteLength(options.remoteHost.host));
buff.writeString(options.remoteHost.host);
}
// Port
buff.writeUInt16BE(options.remoteHost.port);
// Data
buff.writeBuffer(options.data);
return buff.toBuffer();
}
示例3: sendSocks4InitialHandshake
/**
* Sends initial Socks v4 handshake request.
*/
private sendSocks4InitialHandshake() {
const userId = this._options.proxy.userId || '';
const buff = new SmartBuffer();
buff.writeUInt8(0x04);
buff.writeUInt8(SocksCommand[this._options.command]);
buff.writeUInt16BE(this._options.destination.port);
// Socks 4 (IPv4)
if (net.isIPv4(this._options.destination.host)) {
buff.writeBuffer(ip.toBuffer(this._options.destination.host));
buff.writeStringNT(userId);
// Socks 4a (hostname)
} else {
buff.writeUInt8(0x00);
buff.writeUInt8(0x00);
buff.writeUInt8(0x00);
buff.writeUInt8(0x01);
buff.writeStringNT(userId);
buff.writeStringNT(this._options.destination.host);
}
this._nextRequiredPacketBufferSize =
SOCKS_INCOMING_PACKET_SIZES.Socks4Response;
this._socket.write(buff.toBuffer());
}