當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。