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


TypeScript Socket.write方法代码示例

本文整理汇总了TypeScript中net.Socket.write方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Socket.write方法的具体用法?TypeScript Socket.write怎么用?TypeScript Socket.write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net.Socket的用法示例。


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

示例1: _write_chunk

 protected _write_chunk(messageChunk: Buffer) {
     if (this._socket !== null) {
         this.bytesWritten += messageChunk.length;
         this.chunkWrittenCount++;
         this._socket.write(messageChunk);
     }
 }
开发者ID:node-opcua,项目名称:node-opcua,代码行数:7,代码来源:tcp_transport.ts

示例2: send_command

function send_command(command: protocol.Command) {
  const buffer = JSON.stringify(command);
  const send_command = buffer + '\0';
  client.write(send_command, 'utf8', obj => {
    console.log(`Send command: '${send_command}'`);
  });
}
开发者ID:lochbrunner,项目名称:charlie,代码行数:7,代码来源:index.ts

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: readByte

function readByte(socket: Socket, offset: number, onResult: (readable: boolean, value?: number)=>void) {
  //validate
  if (offset < 0 || offset > 0xffff) {
    throw new RangeError("Offset must be a 16-bit integer from 0x0000 to 0xffff, inclusive");
  }
  //send
  socket.once('data', gotData);
  socket.once('error', gotError);
  let timeout = setTimeout(retry, 10000);
  function removeListeners() {
    socket.removeListener('data', gotData);
    socket.removeListener('error', gotError);
    if (timeout) {
      clearTimeout(timeout);
      timeout = null;
    }
  }

  let message = Checksum.attach(`r${to4hex(offset)}0001`);
  log.outbound(message);
  socket.write(message);

  function retry() {
    removeListeners();
    log.info('Retrying...');
    setImmediate(readByte, socket, offset, onResult);
  }

  function gotError(err) {
    log.error(err);
    removeListeners();
  }

  function gotData(data) {
    if (data) data = String(data);
    log.inbound(data);
    let m = null;
    try {
      m = new Message(data);
    } catch (ex) {
      log.error(ex);
      retry();
      return;
    }
    removeListeners();
    let isReadable = m.bytes.length() > 4;
    if(isReadable) {
      setImmediate(onResult, true, m.bytes.getByte(4));
    } else {
      setImmediate(onResult, false, null);
    }
  }

}
开发者ID:jffry,项目名称:rocket-r60v,代码行数:54,代码来源:measure.ts

示例9:

process.stdin.on('readable', () => {
  let chunk = process.stdin.read()
  if (chunk !== null) {
    if (isConnected) {
      client.write(chunk)
    } else {
      client.on('connect', () => {
        client.write(chunk)
      })
    }
  }
})
开发者ID:dotty-staging,项目名称:dotty,代码行数:12,代码来源:passthrough-server.ts

示例10: 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


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