本文整理汇总了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);
}
}
示例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}'`);
});
}
示例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");
}
}
});
示例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);
});
示例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);
});
示例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);
});
示例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();
});
示例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);
}
}
}
示例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)
})
}
}
})
示例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);
}
}
})();