--客户端死循环读取tcp数据  add by: liang  2019-11-15
function run_read_qr()
    local sIP = ui:getSetting_l('qr_code_from_ip');
    if #sIP <= 0 then
        ui:setSetting_l('qr_code_from_ip', '');
        return;
    end
    local sPort = ui:getSetting_l('qr_code_from_port');
    if #sPort <= 0 then
        ui:setSetting_l('qr_code_from_port', '');
        return;
    elseif tonumber(sPort) == nil then
        return;
    end

    local tcp = CTNLuaTcpClient();
    tcp:setServer(tonumber(sPort), sIP);

    local sv = CTNString();
    local sDlgUI = CTNString();
    local sDlgName = CTNString();
    local sTmp = '';
    while true do
    while true do
        if ui:allThreadStop() then return end
        --if ui:getActiveDialog(sDlgUI, sDlgName) then--返回当前窗口是不是活跃窗口,有可能显示的不是当前页签或者缩小在任务栏
            sv:set('');

            if tcp:isLogin() == false then
                if tcp:login() == false then
                    break;
                end
            end

            tcp:recvMsg(sv, '\r', 1000);--如果字符串中存在\r读取出来,否则读取返回空,第三个参数为超时时间
            if string.len(sv:get()) > 0 then
                sTmp = sv:get();
                print('读取到:'..sTmp);
                sTmp = string.gsub(sTmp, '\r', '');
                sTmp = string.gsub(sTmp, '\n', '');

                ui:threadChangeValue('调用主线程函数()');
            end
        --else
            cutil:sleep(200);
        --end
        break;
    end
    end
end

ui:run('run_read_qr()', '');
Copyright © TouchNet 2015 all right reserved,powered by Gitbook最后修订时间: 2022-06-21 09:21:04

results matching ""

    No results matching ""