当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript net.Socket类代码示例

本文整理汇总了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();
        });
开发者ID:bespoken,项目名称:bst,代码行数:17,代码来源:socket-handler-test.ts

示例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();
			});
		});
	});
开发者ID:MaxMEllon,项目名称:SavannaTalk,代码行数:45,代码来源:main.ts

示例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);
		});
	}
开发者ID:dcby,项目名称:smtp-receiver,代码行数:9,代码来源:Loop.ts

示例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]
}
开发者ID:josephg,项目名称:statecraft,代码行数:9,代码来源:tcpclient.ts

示例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(() => { });
   });
 }
开发者ID:svi3c,项目名称:rx-messaging,代码行数:18,代码来源:ClientConnector.ts

示例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);
			}
		}
	})();
开发者ID:miniflycn,项目名称:tsun,代码行数:18,代码来源:index.ts

示例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);
 });
开发者ID:zhoupan,项目名称:idevice-app-launcher,代码行数:9,代码来源:runApp.ts

示例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);
 });
开发者ID:Paradox-Cascade,项目名称:vscode-cordova,代码行数:9,代码来源:cordovaIosDeviceLauncher.ts

示例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);
 });
开发者ID:veeraragavanv,项目名称:vscode-react-native,代码行数:9,代码来源:deviceRunner.ts

示例10: setTimeout

 setTimeout(() => {
     socket.emit('data', part1);
     setTimeout(() => {
         socket.emit('data', part2);
         setTimeout(() => {
             socket.emit('data', part3);
         }, 100);
     }, 100);
 }, 100);
开发者ID:Heresiarch88,项目名称:vscode-php-debug,代码行数:9,代码来源:dbgp.ts


注:本文中的net.Socket类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。