本文整理汇总了TypeScript中net.Socket类的典型用法代码示例。如果您正苦于以下问题:TypeScript Socket类的具体用法?TypeScript Socket怎么用?TypeScript Socket使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Socket类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: it
it("Sends callback on close", function (done) {
const client = new net.Socket();
const socketHandler = SocketHandler.connect("localhost", 10001,
function (error: any) {
assert(error);
done();
},
function () {}
);
socketHandler.onCloseCallback = function() {
console.log("Closed!");
done();
};
client.end();
});
示例2: Buffer
messages.forEach((message: IMessage) => {
if (!config.readChat) {
return;
}
if ((!config.readMessage) && message.type === MESSAGE_TYPE_MESSAGE) {
return;
}
if ((!config.readBalloon) && message.type === MESSAGE_TYPE_BALLOON) {
return;
}
if ((!config.readAnnounce) && message.type === MESSAGE_TYPE_ANNOUNCE) {
return;
}
if ((!config.readLikes) && message.type === MESSAGE_TYPE_LIKES) {
return;
}
let client: Socket = new net.Socket();
client.setEncoding('binary');
client.on("error", () => {
mainWindow.webContents.send("error", "棒読みちゃんに接続できません。棒読みちゃんが起動していることを確認してください。");
});
client.connect(50001, "localhost", () => {
let text: string = message.message;
if (message.type === MESSAGE_TYPE_LIKES) {
text = "Eねされました。";
} else {
text = text.replace(/https?:\/\/[\-_\.!~*'\(\)a-zA-Z0-9;/\?:@&=\+\$,%#]+/g, "(URL省略)");
}
if (config.readNickname) {
text += " " + message.nickname;
}
let textBuffer: Buffer = new Buffer(text, 'utf8');
let headerBuffer: Buffer = new Buffer(15);
headerBuffer.writeUInt16LE(0x0001, 0); // command
headerBuffer.writeUInt16LE(0xFFFF, 2); // speed
headerBuffer.writeUInt16LE(0xFFFF, 4); // tone
headerBuffer.writeUInt16LE(0xFFFF, 6); // volume
headerBuffer.writeUInt16LE(0x0000, 8); // voice
headerBuffer.writeUInt8(0x00, 10); // charset
headerBuffer.writeUInt32LE(textBuffer.length, 11); // length
client.write(headerBuffer.toString('binary') + textBuffer.toString('binary'), 'binary', () => {
client.destroy();
});
});
});
示例3: constructor
constructor(sock: Socket) {
this._sock = sock;
this._sock.once("error", err => {
if (!this._d)
this._d = defer();
if (this._d.pending)
this._d.reject(err);
});
}
示例4:
const wrap = <R, W>(socket: Socket): [TinyReader<R>, TinyWriter<W>] => {
const writer = wrapWriter<W>(socket, msgpack.encode)
const readStream = msgpack.createDecodeStream()
socket.pipe(readStream)
const reader = wrapReader<R>(readStream)
return [reader, writer]
}
示例5: attachListenersToSocket
private attachListenersToSocket() {
this.socket.on("connect", () => {
this.eventsObserver.next({ type: ConnectionEventType.connect, payload: this.socket });
this.connectionBackoff = null;
});
this.socket.on("error", (err) => {
this.socket.destroy();
this.eventsObserver.next({ type: ConnectionEventType.error, payload: err });
});
this.socket.on("close", () => {
this.socket.removeAllListeners();
this.socket = null;
this.eventsObserver.next({ type: ConnectionEventType.close });
this.connectionBackoff = this.connectionBackoff || this.reconnectAlgorithm && this.reconnectAlgorithm();
this.connect(this.connectionBackoff ? this.connectionBackoff.next().value : 0)
.catch(() => { });
});
}
示例6: function
return (async function(): Promise<any> {
let inst = new ChildModel(graph);
if (
inst.verify &&
!(await verify())
) {
// need login
res && res.end(JSON.stringify({ seq: i, code: 100000 }));
} else {
let result = await inst.get(graph.param);
try {
let data = JSON.stringify({ seq: i, result: result });
res && res.write(data);
} catch(e) {
console.error(e);
}
}
})();
示例7: function
socket.connect(portNumber, "localhost", function(): void {
// set argument 0 to the (encoded) path of the app
const cmd: string = IosAppRunnerHelper.makeGdbCommand("A" + encodedPath.length + ",0," + encodedPath);
initState++;
socket.write(cmd);
setTimeout(function(): void {
deferred1.reject("DeviceLaunchTimeout");
}, appLaunchStepTimeout);
});
示例8: function
socket.connect(portNumber, 'localhost', function (): void {
// set argument 0 to the (encoded) path of the app
let cmd: string = CordovaIosDeviceLauncher.makeGdbCommand('A' + encodedPath.length + ',0,' + encodedPath);
initState++;
socket.write(cmd);
setTimeout(function (): void {
deferred1.reject('Timeout launching application. Is the device locked?');
}, appLaunchStepTimeout);
});
示例9: setTimeout
socket.connect(portNumber, "localhost", () => {
// set argument 0 to the (encoded) path of the app
const cmd: string = this.makeGdbCommand("A" + encodedPath.length + ",0," + encodedPath);
initState++;
socket.write(cmd);
setTimeout(function(): void {
deferred1.reject(new Error("Timeout launching application. Is the device locked?"));
}, appLaunchStepTimeout);
});
示例10: setTimeout
setTimeout(() => {
socket.emit('data', part1);
setTimeout(() => {
socket.emit('data', part2);
setTimeout(() => {
socket.emit('data', part3);
}, 100);
}, 100);
}, 100);