本文整理汇总了TypeScript中net.Socket.emit方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Socket.emit方法的具体用法?TypeScript Socket.emit怎么用?TypeScript Socket.emit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.Socket
的用法示例。
在下文中一共展示了Socket.emit方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: setTimeout
setTimeout(() => {
socket.emit('data', part1);
setTimeout(() => {
socket.emit('data', part2);
setTimeout(() => {
socket.emit('data', part3);
}, 100);
}, 100);
}, 100);
示例2: it
it('should error on invalid XML', () => new Promise((resolve, reject) => {
conn.on('error', (error: Error) => {
assert.isDefined(error);
assert.instanceOf(error, Error);
resolve();
});
conn.once('message', (document: XMLDocument) => {
reject(new Error('emitted message event'));
});
socket.emit('data', makePacket('<</<<><>>><?><>'));
}));
示例3: Promise
return new Promise(async (resolve, reject) => {
let videoData: any = await this.getVideoInfo(ytId);
let redisFormatted = await this.formatForRedis('videos', ytId, videoData);
// console.log('f', redisFormatted);
redis.hmset(key, redisFormatted.videoId, redisFormatted.videoString, async (err) => {
if (err) {
reject(err);
}
let addedVideo = await this.getById('videos', redisFormatted.videoId);
resolve(addedVideo);
});
this.io.emit('VIDEOS_MESSAGE', { message: 'added' });
});
示例4: String
redis.HDEL('videos', String(videoId), async (err, reply) => {
if (err) {
reject(err);
}
if (reply === 1) {
let v = await this.getAll('videos');
await this.reorderAll('videos');
let added = await this.getById('videos', videoId);
resolve(added);
} else {
resolve({
message: reply
});
}
this.io.emit('VIDEOS_MESSAGE', { message: 'deleted' });
});
示例5: while
client.on('data', (data: string) => {
// First four characters indicate length
data = remaining_code + data;
const length = data.length;
while (true) {
const chunkLength = parseInt(data.substr(0, 4));
if (isNaN(chunkLength) || chunkLength > length + 4) {
remaining_code = data;
break;
}
const chunk = data.substr(4, chunkLength);
data = data.substr(4 + chunkLength);
if (chunk.length > 0) {
try {
client.emit('event', JSON.parse(chunk));
} catch (e) {
console.log(`Could not parse event Json '${chunk}': ${e}`);
}
}
}
});
示例6: if
});
_socket = _socket.addListener("lookup", (err, address, family, host) => {
error = err;
if (typeof family === 'string') {
str = family;
} else if (typeof family === 'number') {
num = family;
}
str = host;
});
_socket = _socket.addListener("timeout", () => { });
/// emit
bool = _socket.emit("close", bool);
bool = _socket.emit("connect");
bool = _socket.emit("data", buffer);
bool = _socket.emit("drain");
bool = _socket.emit("end");
bool = _socket.emit("error", error);
bool = _socket.emit("lookup", error, str, str, str);
bool = _socket.emit("lookup", error, str, num, str);
bool = _socket.emit("timeout");
/// on
_socket = _socket.on("close", had_error => {
bool = had_error;
});
_socket = _socket.on("connect", () => { });
_socket = _socket.on("data", data => {
示例7: processRequest
processRequest(request: FacebookRequest, callback: ((err: any, info: any) => void)): void {
let message = this.messageParser.parseMessage(request.message.text);
message.sender = request.recipient;
message.id = v1();
this.endpoint.emit(JSON.stringify(message));
};
示例8:
this._outSocket.connect(term.conout, () => {
// TODO: Emit event on agent instead of socket?
// Emit ready event.
this._outSocket.emit('ready_datapipe');
});