當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript Socket.end方法代碼示例

本文整理匯總了TypeScript中net.Socket.end方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Socket.end方法的具體用法?TypeScript Socket.end怎麽用?TypeScript Socket.end使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在net.Socket的用法示例。


在下文中一共展示了Socket.end方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: function

 socket.on("data", function(data: any): void {
     data = data.toString();
     while (data[0] === "+") { data = data.substring(1); }
     // Acknowledge any packets sent our way
     if (data[0] === "$") {
         socket.write("+");
         if (data[1] === "W") {
             // The app process has exited, with hex status given by data[2-3] 
             const status: number = parseInt(data.substring(2, 4), 16);
             endStatus = status;
             socket.end();
             if (sessionEndCallback) {
                 sessionEndCallback(false);
             }
         } else if (data[1] === "X") {
             // The app process exited because of signal given by data[2-3]
             const signal: number = parseInt(data.substring(2, 4), 16);
             endSignal = signal;
             socket.end();
             if (sessionEndCallback) {
                 sessionEndCallback(false);
             }
         } else if (data[1] === "T") {
             // The debugger has stopped the process for some reason.
             // The message includes register contents and stop signal and other data,
             // but for our purposes it is opaque
             socket.end();
             if (sessionEndCallback) {
                 sessionEndCallback(true);
             }
         } else if (data.substring(1, 3) === "OK") {
             // last command was received OK;
             if (initState === 1) {
                 deferred1.resolve(socket);
             } else if (initState === 2) {
                 deferred2.resolve(socket);
             } else if (initState === 3) {
                 // iOS 10 seems to have changed how output is reported over the debugging channel
                 // We no longer get the "O<message>#<hash>" message that we expected in the past,
                 // although the app launches correctly. Instead we assume that if we get the OK
                 // message that the app is probably launched.
                 deferred3.resolve(socket);
             }
         } else if (data[1] === "O") {
             // STDOUT was written to, and the rest of the input until reaching a '#' is a hex-encoded string of that output
             if (initState === 3) {
                 deferred3.resolve(socket);
                 initState++;
             }
         } else if (data[1] === "E") {
             // An error has occurred, with error code given by data[2-3]: parseInt(data.substring(2, 4), 16)
             deferred1.reject("UnableToLaunchApp");
             deferred2.reject("UnableToLaunchApp");
             deferred3.reject("UnableToLaunchApp");
         }
     }
 });
開發者ID:Microsoft,項目名稱:idevice-app-launcher,代碼行數:57,代碼來源:runApp.ts

示例2: disconnect

    /**
     * disconnect the TCP layer and close the underlying socket.
     * The ```"close"``` event will be emitted to the observers with err=null.
     *
     * @method disconnect
     * @async
     * @param callback
     */
    public disconnect(callback: ErrorCallback): void {

        assert(_.isFunction(callback), "expecting a callback function, but got " + callback);

        if (this._disconnecting) {
            callback();
            return;
        }

        assert(!this._disconnecting, "TCP Transport has already been disconnected");
        this._disconnecting = true;

        // xx assert(!this._theCallback,
        //              "disconnect shall not be called while the 'one time message receiver' is in operation");
        this._cleanup_timers();

        if (this._socket) {
            this._socket.end();
            this._socket.destroy();
            // xx this._socket.removeAllListeners();
            this._socket = null;
        }
        setImmediate(() => {
            this.on_socket_ended(null);
            callback();
        });
    }
開發者ID:node-opcua,項目名稱:node-opcua,代碼行數:35,代碼來源:tcp_transport.ts

示例3: function

 process.on('exit', function () {
   try {
     log.info('Terminating socket...');
     sock.end();
     sock.destroy();
   } catch (ex) {
     //nop
   }
 });
開發者ID:jffry,項目名稱:rocket-r60v,代碼行數:9,代碼來源:measure.ts

示例4: Date

 let server: Server = net.createServer((socket: Socket) => {
     let date: Date = new Date();
     let yyyy: string = date.getFullYear().toString();
     let MM: string = ("0" + (date.getMonth() + 1)).slice(-2);
     let dd: string = ("0" + date.getDate()).slice(-2);
     let hh: string = ("0" + date.getHours()).slice(-2);
     let mm: string = ("0" + date.getMinutes()).slice(-2);
     socket.write(yyyy + "-" + MM + "-" + dd + " " + hh + ":" + mm);
     socket.end();
 });
開發者ID:kyanro,項目名稱:nodeschool-learnyounode,代碼行數:10,代碼來源:main.ts

示例5: function

            client.connect(10000, "localhost", function () {
                new SocketHandler(client, function (message: any) {

                });

                client.end();

                setTimeout(function () {
                    done();
                }, 200);
            });
開發者ID:bespoken,項目名稱:bst,代碼行數:11,代碼來源:socket-handler-test.ts

示例6: function

 socket.on("data", function(data: any): void {
     data = data.toString();
     while (data[0] === "+") { data = data.substring(1); }
     // Acknowledge any packets sent our way
     if (data[0] === "$") {
         socket.write("+");
         if (data[1] === "W") {
             // The app process has exited, with hex status given by data[2-3]
             let status: number = parseInt(data.substring(2, 4), 16);
             endStatus = status;
             socket.end();
         } else if (data[1] === "X") {
             // The app rocess exited because of signal given by data[2-3]
             let signal: number = parseInt(data.substring(2, 4), 16);
             endSignal = signal;
             socket.end();
         } else if (data.substring(1, 3) === "OK") {
             // last command was received OK;
             if (initState === 1) {
                 deferred1.resolve(socket);
             } else if (initState === 2) {
                 deferred2.resolve(socket);
             }
         } else if (data[1] === "O") {
             // STDOUT was written to, and the rest of the input until reaching a "#" is a hex-encoded string of that output
             if (initState === 3) {
                 deferred3.resolve(socket);
                 initState++;
             }
         } else if (data[1] === "E") {
             // An error has occurred, with error code given by data[2-3]: parseInt(data.substring(2, 4), 16)
             const error = new Error("Unable to launch application.");
             deferred1.reject(error);
             deferred2.reject(error);
             deferred3.reject(error);
         }
     }
 });
開發者ID:veeraragavanv,項目名稱:vscode-react-native,代碼行數:38,代碼來源:deviceRunner.ts

示例7: it

        it("Sends callback on failure to connect", function (done) {
            const client = new net.Socket();

            SocketHandler.connect("localhost", 10001,
                function (error: any) {
                    assert(error);
                    done();
                },
                function () {

                }
            );

            client.end();
        });
開發者ID:bespoken,項目名稱:bst,代碼行數:15,代碼來源:socket-handler-test.ts

示例8: return

	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

示例9: combo

export async function combo(describe: string, res: Socket, req?: ServerRequest) {
	let list = parse(describe),
		headers = req.headers || {},
		cookies: { [key: string]: string } = { "uin": '123', "skey": '321' }, // cookie.parse(headers['Cookie']),
		verify = createVerify({ uin: uin(cookies), skey: skey(cookies) }),
		promise,
		promises: Promise<any>[] = [];
	for (var i = 0, l = list.length; i < l; i++) {
		promise = _wrap(list[i], i, res, verify);
		if (promise) promises.push(promise);
	}
	try {
		await Promise.all(promises);
	} catch(e) {
		console.error(e);
	} finally {
		res && res.end();
	}
}
開發者ID:miniflycn,項目名稱:tsun,代碼行數:19,代碼來源:index.ts


注:本文中的net.Socket.end方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。