随便测试
一个行
CLICK ME
- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didSendBodyData:(int64_t)bytesSent totalBytesSent:(int64_t)totalBytesSent totalBytesExpectedToSend:(int64_t)totalBytesExpectedToSend {
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
UILabel *label = (UILabel *)[cell viewWithTag:104];
dispatch_async(dispatch_get_main_queue(), ^{
if((float)totalBytesSent / totalBytesExpectedToSend == 1.0f) {
label.text = @"上传成功";
}
else {
label.text = [NSString stringWithFormat:@"上传中:%.0f%%",100*(float)totalBytesSent / totalBytesExpectedToSend];
}
});
}
'use strict';
const Host = '47.112.172.203';
const User = 'root';
const Password = 'Xw8323fox~';
const Port = 3306;
const DB = 'hxw_testdb';
const Table = 'ConnectionID_List';
const mysql = require('mysql');
const dayjs = require('dayjs');
function wrapPromise(connection, sql) {
return new Promise((resolve, reject) => {
connection.query(sql, function (error, results, fields) {
if (error) {
reject(error);
}
resolve(results);
});
});
}
async function record_connectionID(connectionID) {
console.log("Start record_connectionID function");
console.log("connectionID is", connectionID);
const connection = mysql.createConnection({
host: Host,
user: User,
password: Password,
database: DB,
port: Port
});
// Save the connection ID into datavase, 把 connection ID 存到数据库
const now = new dayjs();
const nowStr = now.format("YYYY-MM-DD HH:mm:ss");
let addsql = `insert INTO ${Table} (\`ConnectionID\`, \`Date\`, \`Extra\`) VALUES ('${connectionID}', '${nowStr}', '囍囍囍')`;
await wrapPromise(connection, addsql);
connection.end();
}
exports.main_handler = async (event, context, callback) => {
console.log("event is", event);
console.log("event log end");
if (!event.requestContext) {
return { errNo: 101, errMsg: "not found request context" };
}
if (!event.websocket) {
return { errNo: 102, errMsg: "not found web socket" };
}
let connectionID = event["websocket"]["secConnectionID"];
let retmsg = {};
retmsg["errNo"] = 0;
retmsg["errMsg"] = "ok";
retmsg["websocket"] = {
action: "connecting",
secConnectionID: connectionID
};
// Recording the new connectionID into database, 在数据库中记录新的connectionID
console.log("Start DB Request", new dayjs().format("YYYY-MM-DD HH:mm:ss"));
await record_connectionID(connectionID);
console.log("Finish DB Request", new dayjs().format("YYYY-MM-DD HH:mm:ss"));
console.log(
"connecting: connection id",
event["websocket"]["secConnectionID"]
);
return retmsg;
}