當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。