当前位置: 首页>>代码示例>>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;未经允许,请勿转载。