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


TypeScript net.connect函數代碼示例

本文整理匯總了TypeScript中net.connect函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript connect函數的具體用法?TypeScript connect怎麽用?TypeScript connect使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


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

示例1: reconnect

const module: reconnect.CustomModule<NetConnectOpts | string | number, Socket> = reconnect(arg => {
    // TS can't resolve passing even the simplest union types to function overloads :-/
    // (see TS issue #14107)
    if (typeof arg === "string") {
        return connect(arg);
    } else if (typeof arg === "number") {
        return connect(arg);
    } else {
        return connect(arg);
    }
});
開發者ID:Jeremy-F,項目名稱:DefinitelyTyped,代碼行數:11,代碼來源:reconnect-core-tests.ts

示例2: tryToConnect

        function tryToConnect() {
            if (timedOut) {
                return;
            }

            var socket = net.connect({ port: port }, () => {
                if (timedOut) {
                    return;
                }

                resolve();
                socket.end();
                clearTimeout(handle);
            });
            socket.on("error", error => {
                if (timedOut) {
                    return;
                }

                if (error.code === "ECONNREFUSED" && !timedOut) {
                    setTimeout(() => {
                        tryToConnect();
                    }, 10);
                    return;
                }

                clearTimeout(handle);
                reject(`Connection failed due to ${JSON.stringify(error)}`);
            });
        }
開發者ID:Erguotou,項目名稱:pythonVSCode,代碼行數:30,代碼來源:OnPortOpenedHandler.ts

示例3: sendMessage

    public sendMessage(message: ExtensionMessage, args?: any[]): Q.Promise<any> {
        let deferred = Q.defer<any>();
        let messageWithArguments: MessageWithArguments = { message: message, args: args };
        let body = "";

        let pipePath = HostPlatform.getExtensionPipePath();
        let socket = net.connect(pipePath, function() {
            let messageJson = JSON.stringify(messageWithArguments);
            socket.write(messageJson);
        });

        socket.on("data", function(data: any) {
            body += data;
        });

        socket.on("error", function(data: any) {
            deferred.reject(new Error("An error ocurred while handling message: " + ExtensionMessage[message]));
        });

        socket.on("end", function() {
            try {
                if (body === ErrorMarker) {
                    deferred.reject(new Error("An error ocurred while handling message: " + ExtensionMessage[message]));
                } else {
                    let responseBody: any = body ? JSON.parse(body) : null;
                    deferred.resolve(responseBody);
                }
            } catch (e) {
                deferred.reject(e);
            }
        });

        return deferred.promise;
    }
開發者ID:KeithLee208,項目名稱:vscode-react-native,代碼行數:34,代碼來源:extensionMessaging.ts

示例4: tryToConnect

        function tryToConnect() {
            if (timedOut) {
                return;
            }

            var socket = net.connect({ port: port }, () => {
                if (timedOut) {
                    return;
                }

                socket.end();
                clearTimeout(handle);
                resolve();
            });
            socket.on("error", error => {
                if (timedOut) {
                    return;
                }

                if (error.code === "ECONNREFUSED" && !timedOut) {
                    setTimeout(() => { tryToConnect(); }, 10);
                    return;
                }

                clearTimeout(handle);
                if (error && error.message) {
                    error.message = `connection failed (${error.message})`;
                }
                reject(error);
            });
        }
開發者ID:airstep,項目名稱:javaVSCode,代碼行數:31,代碼來源:waitForPortToOpen.ts

示例5: if

 const checkServer = () => {
   if (all_done || server_ready) {
     if (client != null) {
       client.destroy()
       client = null
     }
   } else if (num_server_attempts > (server_timeout_millis / 100)) {
     promise.reject(new Error("Failed to connect to the server"))
   } else if (client != null) {
     // still waiting on a client we already have...
     setTimeout(checkServer, 100)
   } else {
     num_server_attempts = num_server_attempts + 1
     client = net.connect(port, 'localhost')
     client.on('error', () => {
       client!.destroy()
       client = null
       if (!(all_done || server_ready))
         setTimeout(checkServer, 100)
     })
     client.on('connect', () => {
       client!.destroy()
       client = null
       server_ready = true
       setTimeout(runF, 0)
     })
   }
 }
開發者ID:jsignell,項目名稱:bokeh,代碼行數:28,代碼來源:connection.ts

示例6: connect

		return new Promise<void>((resolve, reject) => {
			var client: Socket = connect(port, () => {
				console.log('connected to firefox');
				this._state = 'connected';
				this.setupSocket(client);
				resolve();
			});
		});
開發者ID:yurydelendik,項目名稱:vscode-ff-debug,代碼行數:8,代碼來源:ffProtocol.ts

示例7: connectToPort

	public async connectToPort(data: Mobile.IConnectToPortData): Promise<net.Socket> {
		try {
			const socket = net.connect(data.port);
			return socket;
		} catch (e) {
			this.$logger.debug(e);
		}
	}
開發者ID:NativeScript,項目名稱:nativescript-cli,代碼行數:8,代碼來源:ios-emulator-services.ts

示例8:

 let serverOptions = () => {
     // Connect to language server via socket
     let socket = net.connect(connectionInfo);
     let result: StreamInfo = {
         writer: socket,
         reader: socket
     };
     return Promise.resolve(result);
 };
開發者ID:cdietrich,項目名稱:xtext-languageserver-example,代碼行數:9,代碼來源:extension.ts

示例9:

	let serverInfo = () => {
		// Connect to the language server via a socket channel
		let socket = net.connect(serverOptions);
		let result: StreamInfo = {
			writer: socket,
			reader: socket
		}
		return Promise.resolve(result);
	}
開發者ID:RealTYPICAL,項目名稱:xtext-core,代碼行數:9,代碼來源:extension.ts

示例10: Promise

    return new Promise((resolve, reject) => {
      const socket = net.connect(8899, device.config.host, (err: any) => {
        if (err) return reject(err)

        socket.write(new Buffer(fullCommand), (err: any) => {
          socket.destroy()
          if (err) return reject(err)
          resolve()
        })
      })
    })
開發者ID:Pajn,項目名稱:RAXA,代碼行數:11,代碼來源:index.ts


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