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


TypeScript net.createServer函数代码示例

本文整理汇总了TypeScript中net.createServer函数的典型用法代码示例。如果您正苦于以下问题:TypeScript createServer函数的具体用法?TypeScript createServer怎么用?TypeScript createServer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了createServer函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: test

        test("should successfully send a message with args", function(done: MochaDone) {
            const args = ["android"];
            let receivedMessage: ExtensionMessage;
            let receivedArgs: any;

            mockServer = net.createServer(function(client: net.Socket): void {
                mockServer.close();
                client.on("data", function(data: Buffer) {
                    const messageData: any = JSON.parse(data.toString("utf8"));
                    client.end();

                    receivedMessage = messageData.message;
                    receivedArgs = messageData.args;
                });
            });

            mockServer.on("error", done);
            mockServer.listen(port);

            const sender = RemoteExtension.atProjectRootPath(projectRootPath);

            Q({})
                .then(function() {
                    return sender.prewarmBundleCache(args[0]);
                })
                .then(function() {
                    assert.equal(receivedMessage, ExtensionMessage.PREWARM_BUNDLE_CACHE);
                    assert.deepEqual(receivedArgs, args);
                }).done(() => done(), done);
        });
开发者ID:Yu-Che-Gao,项目名称:vscode-react-native,代码行数:30,代码来源:extensionMessaging.test.ts

示例2: test

test('correctly binds to the server and redirects its events.', () => {
  const server = createServer();
  proxifier.bind(server);

  const eventsAndListeners = new Map(
    ['listening', 'error', 'clientError', 'connection'].map(eventName => {
      const listener = jest.fn();
      proxifier.addListener(eventName, listener);

      return [eventName, listener] as [string, () => void];
    })
  );

  for (const [eventName, listener] of eventsAndListeners) {
    expect(listener).not.toHaveBeenCalled();

    // Emit several events, to make sure that server is not being listened with `once`.
    server.emit(eventName, 1, 2, 3, 4);
    server.emit(eventName, 5, 6, 7, 8);

    expect(listener).toHaveBeenCalledTimes(2);
    expect(listener).toHaveBeenCalledWith(1, 2, 3, 4);
    expect(listener).toHaveBeenCalledWith(5, 6, 7, 8);
  }
});
开发者ID:Jaaess,项目名称:kibana,代码行数:25,代码来源:legacy_platform_proxifier.test.ts

示例3: startLsCrashServer

export function startLsCrashServer() {

    let pipe_path = generatePipeName(process.pid.toString(), 'vscode-language-julia-lscrashreports');

    let server = net.createServer(function (connection) {
        let accumulatingBuffer = new Buffer(0);

        connection.on('data', async function (c) {
            accumulatingBuffer = Buffer.concat([accumulatingBuffer, Buffer.from(c)]);
        });

        connection.on('close', async function (had_err) {
            let bufferResult = accumulatingBuffer.toString()
            let replResponse = accumulatingBuffer.toString().split("\n")
            let stacktrace = replResponse.slice(2,replResponse.length-1).join('\n');

            crashReporterQueue.push({exception: {name: replResponse[0], message: replResponse[1], stack: stacktrace}});

            traceEvent('lserror');

            if (enableCrashReporter) {
                sendCrashReportQueue();
            }
            else {
                showCrashReporterUIConsent();
            }
        });
    });

    server.listen(pipe_path);

    return pipe_path;
}
开发者ID:JuliaEditorSupport,项目名称:julia-vscode,代码行数:33,代码来源:telemetry.ts

示例4: resolve

                PortFinder.getPort((err, port) => {
                    let fatJar = Path.resolve(context.extensionPath, "out", "fat-jar.jar");
                    
                    let args = [
                        '-cp', fatJar, 
                        '-Djavacs.port=' + port,
                        'org.javacs.Main'
                    ];
                    
                    console.log(javaExecutablePath + ' ' + args.join(' '));
                    
                    Net.createServer(socket => {
                        console.log('Child process connected on port ' + port);

                        resolve({
                            reader: socket,
                            writer: socket
                        });
                    }).listen(port, () => {
                        let options = { stdio: 'inherit', cwd: VSCode.workspace.rootPath };
                        
                        // Start the child java process
                        ChildProcess.execFile(javaExecutablePath, args, options);
                    });
                });
开发者ID:alexsaveliev,项目名称:vscode-javac,代码行数:25,代码来源:Main.ts

示例5: constructor

 constructor(options: { dstAddr: string, dstPort?: number, localPort?: number }) {
   let dstAddr = options.dstAddr;
   let dstPort = options.dstPort || defaultServerPort;
   let localPort = options.localPort || defaultServerPort;
   
   let server = net.createServer((socket) => {
     let transitSocket = net.createConnection(dstPort, dstAddr, () => {
       socket.pipe(transitSocket);
       transitSocket.pipe(socket);
     });
     
     function dispose() {
       transitSocket.dispose();
       socket.dispose();
     }
     
     transitSocket.on('end', dispose);
     transitSocket.on('error', dispose);
     socket.on('end', dispose);
     socket.on('error', dispose);
   });
   
   server.on('error', (err) => {
     console.log(err.message);
     process.exit(1);
   });
   
   server.listen(localPort);
 }
开发者ID:52M,项目名称:LightSword,代码行数:29,代码来源:app.ts

示例6: _getPort

    function _getPort(portNumber: number) {
      if (portNumber > 65535) {
        reject(new Error(`There is no port available.`));
      }

      const server = net.createServer();

      server.once('error', (err: Error & {code: string}) => {
        if (err.code !== 'EADDRINUSE') {
          reject(err);
        } else if (port === 0) {
          _getPort(portNumber + 1);
        } else {
          // If the port isn't available and we weren't looking for any port, throw error.
          reject(
            new Error(`Port ${port} is already in use. Use '--port' to specify a different port.`),
          );
        }
      })
      .once('listening', () => {
        server.close();
        resolve(portNumber);
      })
      .listen(portNumber, host);
    }
开发者ID:DevIntent,项目名称:angular-cli,代码行数:25,代码来源:check-port.ts

示例7: start

  async start() {
    const broker = createMqttBroker()
    const server = createServer(broker.handle)
    this.server = server

    this.listenOn(
      plugin.interfaces.MQTT.id,
      plugin.interfaces.MQTT.events.publish.id,
      ({
        clientId,
        topic,
        value,
      }: {
        clientId: string
        topic: string
        value: string
      }) => {
        this.log.debug('Publishing packet', {
          clientId,
          topic,
          payload: value,
          qos: 0,
          retain: false,
        })
        const packet: IPublishPacket = {
          cmd: 'publish',
          topic,
          payload: value,
          qos: 0,
          retain: false,
          dup: false,
        }
        if (clientId) {
          ;(broker.publish as any)(packet, clientId, () => {})
        } else {
          broker.publish(packet, () => {})
        }
      },
    )

    broker.on('publish', (packet, client) => {
      this.log.debug('Received packet', {
        clientId: client && client.id,
        topic: packet.topic,
        value: packet.payload.toString(),
      })
      this.fireEvent(
        plugin.interfaces.MQTT.id,
        plugin.interfaces.MQTT.events.received.id,
        {
          clientId: client && client.id,
          topic: packet.topic,
          value: packet.payload.toString(),
        },
      )
    })

    await new Promise(resolve => server.listen(1883, resolve))
  }
开发者ID:Pajn,项目名称:RAXA,代码行数:59,代码来源:index.ts

示例8: findNextPort

export function findNextPort(port: number) {
  const server = net.createServer();
  return new Promise<number>((resolve) => {
    server.once("close", () => resolve(port));
    server.on("error", () => resolve(findNextPort(port + 1)));
    server.listen(port, () => server.close());
  });
}
开发者ID:iurimatias,项目名称:embark-framework,代码行数:8,代码来源:network.ts


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