从下面的代码中,如何在不中断应用程序显示部分的情况下使运行时监听器运行?当前,当我使用运行时监听器时,显示速度变慢。仅供引用,我是Lua/Corona的新手,也是stackoverflow的新手。

function scene:createScene( event )
        group2 = scrollView.new{ top=topBoundary, bottom=bottomBoundary }

        myImage = display.newImage("imgbg1.png")
        myImage.isVisible =  true
        group2:insert(myImage)

        local yval = 120

        socket,err=socket1.connect("host", port)

        while not err do

            socket:settimeout(1)
            socket:send("runcommand\r\n")

            repeat
              line, err = socket:receive()

              if line then
                no = no + 1

                -- [[ get only the main properties ]] --
                if no >= 5 then
                reply = reply .. line
                end
              end
            until err

            t1 = reply
            loadnsave:saveToJson(t1,filename)
            tsw = loadnsave:loadData(filename)

            local i = 0

            for k, v in pairs(tsw) do
                i = i + 1
                print("\n" .. k , v )
                locy = locy + 20
                imgBase[i] = display.newImage("image.png")
                imgBase[i].x = locx
                imgBase[i].y = locy
                group2:insert(imgBase[i])

                sw[i] = swfunc(tsw[k],k,locy,i)

                group2:insert(sw[i])

                locy = locy + 40 + iHeight
            end

            inity = 1
            initw = 1
        end

    Runtime:addEventListener("enterFrame", swlistener)

end

function swlistener(event)
    local reply2 = ""
    repeat
      line2, err2 = socket:receive()

      if line2 then
        reply2 = reply2 .. line2
      end

    until err2
end

最佳答案

如果我没有记错的话,那么这与运行时监听器无关。它的套接字连接可能会减慢应用程序的运行速度。

我不是100%确信(它会冻结屏幕吗?如果是,那就是问题所在)
如果确实存在套接字连接问题,则可以执行以下一项操作。

  • 如果您的要求是GET/POST请求,请使用异步方法network.request
  • 套接字的
  • disable the so-called Nagle's algorithmsocket:setoption(tcp-nodelay,true)
  • 10-07 13:18
    查看更多