本文整理汇总了TypeScript中net.Socket.end方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Socket.end方法的具体用法?TypeScript Socket.end怎么用?TypeScript Socket.end使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.Socket
的用法示例。
在下文中一共展示了Socket.end方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: 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");
}
}
});
示例2: disconnect
/**
* disconnect the TCP layer and close the underlying socket.
* The ```"close"``` event will be emitted to the observers with err=null.
*
* @method disconnect
* @async
* @param callback
*/
public disconnect(callback: ErrorCallback): void {
assert(_.isFunction(callback), "expecting a callback function, but got " + callback);
if (this._disconnecting) {
callback();
return;
}
assert(!this._disconnecting, "TCP Transport has already been disconnected");
this._disconnecting = true;
// xx assert(!this._theCallback,
// "disconnect shall not be called while the 'one time message receiver' is in operation");
this._cleanup_timers();
if (this._socket) {
this._socket.end();
this._socket.destroy();
// xx this._socket.removeAllListeners();
this._socket = null;
}
setImmediate(() => {
this.on_socket_ended(null);
callback();
});
}
示例3: function
process.on('exit', function () {
try {
log.info('Terminating socket...');
sock.end();
sock.destroy();
} catch (ex) {
//nop
}
});
示例4: 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();
});
示例5: function
client.connect(10000, "localhost", function () {
new SocketHandler(client, function (message: any) {
});
client.end();
setTimeout(function () {
done();
}, 200);
});
示例6: 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]
let status: number = parseInt(data.substring(2, 4), 16);
endStatus = status;
socket.end();
} else if (data[1] === "X") {
// The app rocess exited because of signal given by data[2-3]
let signal: number = parseInt(data.substring(2, 4), 16);
endSignal = signal;
socket.end();
} 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 (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)
const error = new Error("Unable to launch application.");
deferred1.reject(error);
deferred2.reject(error);
deferred3.reject(error);
}
}
});
示例7: it
it("Sends callback on failure to connect", function (done) {
const client = new net.Socket();
SocketHandler.connect("localhost", 10001,
function (error: any) {
assert(error);
done();
},
function () {
}
);
client.end();
});
示例8: 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);
}
}
})();
示例9: combo
export async function combo(describe: string, res: Socket, req?: ServerRequest) {
let list = parse(describe),
headers = req.headers || {},
cookies: { [key: string]: string } = { "uin": '123', "skey": '321' }, // cookie.parse(headers['Cookie']),
verify = createVerify({ uin: uin(cookies), skey: skey(cookies) }),
promise,
promises: Promise<any>[] = [];
for (var i = 0, l = list.length; i < l; i++) {
promise = _wrap(list[i], i, res, verify);
if (promise) promises.push(promise);
}
try {
await Promise.all(promises);
} catch(e) {
console.error(e);
} finally {
res && res.end();
}
}