network.request - all freeze

Hello. I create a little game, and the last 2 months I place it in Google Play: https://play.google.com/store/apps/details?id=synthesis.game.fishing

The game I have a chat every few seconds, I execute network.request and poor connection to the Internet, the game is constantly out in the deep freeze. How to query in a separate thread? Please help, because a project of 33 thousand lines on the verge of complete collapse …

Dear developers! When I was choosing from the many options it is your product, I have not seen any description not like:

  1. You can only write the application offline as any work with the network application proposes.

  2. All application and all timers are carried in one stream

  3. We do not provide technical support to users

It was not written in your advertising …

So why is this so?

Hi @execom.

I’m not sure I understand all your questions, but I’ll try and answer.

  1. With Corona SDK, until you either a) need a plugin, b) need to build for a device or deployment or c) try to access networking functions, you can use Corona SDK offline. But once you need something that requires network access, you are going to have to have network access.  You can either be online or offline while you work on your app depending on the above conditions. If you were to purchase Corona Enterprise, you could do everything off line with the exception of when your app needs networking.

  2. Corona SDK does run on one thread for most things. Somethings like audio I believe run on their own threads. However, Lua does support co-routines which are thread-like.  See: https://coronalabs.com/blog/2015/02/10/tutorial-using-coroutines-in-corona/ 

Many time consuming processes like network.request() use call back listeners which allows the main thread to continue running while it awaits completion in which the main thread picks back up with the call back listener.

  1. Corona Labs provides several layers of support. The first layer is here in the forums. The community is a great resource to figure out almost all the things you need. Staff members, like myself patrol the forums to answer product specific questions and things that may be bugs to determine if you should file a bug report or not. Our community members are really good this part too. We have probably the best community of developers on the Internet!  If you are not finding the help here that you need, we do offer a paid layer of support as well.  To say that we don’t offer technical support is incorrect. We have two developer relations specialists who check the forums multiple times seven days a week including holidays. Our engineering staff even steps in from time to time to directly answer questions. Oh, we also have an IRC channel too.

What leads you to believe that we don’t offer technical support to users?

As far as the game goes, I downloaded it and really didn’t notice any delays. But without seeing your network request code and the code calling your network request, it’s going to be hard to answer you.

BTW: Once a fish hits the bait, how do you real it in?

I am sorry for my second post. I did not know how to answer.

The problem is that the game has a chat, which is once every 6 seconds gets the current line of the room, I do it like this:

http\_headers = {} http\_headers ["Content-Type"] = "application / x-www-form-urlencoded" http\_headers ["Accept-Language"] = "en-US" http\_params = {} http\_params.headers = headers http\_params.timeout = 1 network.request (url, "GET", listenerChat, http\_params)

despite the fact that obviously limits the time 1 second, if the device bad ping request could hinder the execution to ANR

I have to once every 30 seconds to make the change ping, and if it is worse than I do the necessary suspension of all network requests. But in the process of measuring the ping again I come across lags. I get Ping follows:

true\_ping = true --global local old\_tick = system.getTimer() --this code is main.lua local resp\_check = function(event) local ping = system.getTimer() - old\_tick true\_ping = (not event.isError &nbsp;and &nbsp;event.status == 200 and ping \< 500) --quality ping end local req\_ping = function() network.request(host, 'POST', resp\_check, http\_params ) end local check\_ping = function(event) old\_tick = system.getTimer()--start point req\_ping() end timer.performWithDelay( 30000, check\_ping, 0 )--init timer ping req\_ping()--first tick

Apparently, there is a serious bug in Corona handling network request events. How can I be so sure? Check this out…

My app sends a network request to get the game player data of players in a multiplayer game --> and it does this once per second.

When the data comes into my Network Listener, it processes it by sorting it in a manner suitable for display. During my test, I’m sorting just 3 gamers - so it should finish in a handful of milleseconds. My point here is that it doesn’t take a full second and cause a timing issue. Once the code runs, I then run a timer to execute another network request. In this way, I’m always polling the multiplayer game data from the server.

Problem is, the code does not always reach the bottom of the listener. And it’s not because of another event. It simply just doesn’t. However, If I put a one-second delay on the next network request and place it at the start of my network listener code, it works perfectly. So, I can continue on developing my game. However, there is still no answer as to why the code does not always reach the bottom of my network listener.

Is there anything documented anywhere that would cause this to occur? I am experiencing this in the Mac OS Simulator. Is it isolated to the simulator?

What does your network listener function look like?

Does it always not make it to the same place of is the point where it stops variable?

Rob

I found that on the Mac Simulator, syntax errors are not caught in the web listener, such as:

print (string(a))  – this should have been print (tostring(aa))

and

if a==5 then   – if a==nil, no error is shown - code just stops in the listener and it does not continue

This is a real problem in the Mac Simulator, because I am confounded to discover run-time errors on iOS or Android that could have been avoided. Currently, I’m on my own to make sure there are no errors in my code and cannot rely on the Mac simulator.

I just dropped:  print (string(a))

Into a function that’s handling the call back from a network request and it blew up with this error:
 

ERROR: Runtime error /Volumes/Macintosh HD/Media/Projects/CoronaSDK/CoronaWeather/currentConditions.lua:268: attempt to call global 'string' (a table value) stack traceback: [C]: in function 'string' /Volumes/Macintosh HD/Media/Projects/CoronaSDK/CoronaWeather/currentConditions.lua:268: in function \</Volumes/Macintosh HD/Media/Projects/CoronaSDK/CoronaWeather/currentConditions.lua:264\>

Can you post your build.settings?

Have you done something to turn off error trapping?

Are you using a global variable called “debug”

Rob

Good questions.

I have done something to turn off error trapping? NO

Am I using a global variable called “debug”? NO, but I’m using Lua Glider 2.0, which when I startup Corona Simulator, does insert a line 1 in main.lua  adding require “Cider.debugger”

Here is my current build.settings file (some things modified for privacy):
settings = {
    orientation =
    {
        default = “landscapeRight”,
        content = “landscapeRight”,
        supported = { “landscapeLeft”, “landscapeRight”},
    },
    android = {
    largeHeap = true,  --only good for Android version 3.x according to Wilson Wan
        googlePlayGamesAppId = “xxxx”,
        versionCode = “6”,
        versionName = “0.982”,
        facebookAppId = “xxxx”,
        permissions =
        {
            { name = “.permission.C2D_MESSAGE”, protectionLevel = “signature” },
        },
        
        usesPermissions =
        {
            “android.permission.INTERNET”,
            “android.permission.GET_ACCOUNTS”,
            “android.permission.RECEIVE_BOOT_COMPLETED”,
            “com.google.android.c2dm.permission.RECEIVE”,
            “.permission.C2D_MESSAGE”,
            “android.permission.READ_PHONE_STATE”,
            “android.permission.ACCESS_NETWORK_STATE”,
            “android.permission.ACCESS_WIFI_STATE”, --“this seems to remove ERROR: Not trusted server certificate”
            –                          “android.permission.VIBRATE”,
            –                          “android.permission.ACCESS_FINE_LOCATION”,
            –                          “android.permission.ACCESS_COARSE_LOCATION”
            
            “com.android.vending.BILLING”,          – for in app purchase for Google Play
            “com.android.vending.CHECK_LICENSE”,    – for in app purchase for Google Play
        },
    },
    
    plugins = {
    [“plugin.facebook.v4”] =
    {
        publisherId = “com.coronalabs”
    },
        
        [“plugin.notifications”] =
        {
            publisherId = “com.coronalabs”
        },
        
    –        [“CoronaProvider.gameNetwork.apple”] =
    –        {
    –            publisherId = “com.coronalabs”,
    –            supportedPlatforms = { iphone=true, [“iphone-sim”]=true },
    –        },
        
    –        [“CoronaProvider.gameNetwork.google”] =
    –        {
    –            publisherId = “com.coronalabs”,
    –            supportedPlatforms = { android=true },
    –        },
        
    –        [“plugin.google.play.services”] =
    –        {
    –            publisherId = “com.coronalabs”,
    –            supportedPlatforms = { android=true, [“android-kindle”]=true },
    –        },
        
        [“CoronaProvider.native.popup.safariView”] =
        {
            publisherId = “com.coronalabs”,
            supportedPlatforms = { iphone=true, [“iphone-sim”]=true }
        },
        
        [“plugin.google.iap.v3”] =
        {
            – required
            publisherId = “com.coronalabs”,
            supportedPlatforms = { android=true }
        },
    },
    
    iphone = {
        plist = {
        ITSAppUsesNonExemptEncryption=false,
        UIApplicationExistsOnSuspend = false,
        CFBundleDisplayName = “PlayBible”,
            CFBundleName = “PlayBible”,
            CFBundleShortVersionString = “0.98”,
        FacebookAppID=“xxxx”,
        CFBundleURLTypes =
        { {
            CFBundleURLSchemes = {“fbxxxx”,}
        } },
        [“URL types”] =
        {
        item =
        {
            [“URL Schemes”] = { [“Item 0”] = “fbxxxx” },
        },
        },
            NSAppTransportSecurity =
            {
                NSExceptionDomains =
                {
                    [“facebook.com”] =
            {
                NSIncludesSubdomains = true,
                        NSThirdPartyExceptionRequiresForwardSecrecy = false
                    },
            [“fbcdn.net”] =
            {
                NSIncludesSubdomains = true,
                        NSThirdPartyExceptionRequiresForwardSecrecy = false
                    },
            [“akamaihd.net”] =
            {
                NSIncludesSubdomains = true,
                        NSThirdPartyExceptionRequiresForwardSecrecy = false
                    },
            [“xxxx.org”] =
                    {
                        NSIncludesSubdomains = true,
                        NSThirdPartyExceptionAllowsInsecureHTTPLoads = true
                    },
            [“xxxx.com”] =
                    {
                        NSIncludesSubdomains = true,
                        NSThirdPartyExceptionAllowsInsecureHTTPLoads = true
                    },
            [“coronalabs.com”] =
                    {
                        NSIncludesSubdomains = true,
                        NSThirdPartyExceptionAllowsInsecureHTTPLoads = true
                    },
            [“xxxx.org”] =
                    {
                        NSIncludesSubdomains = true,
                        NSThirdPartyExceptionAllowsInsecureHTTPLoads = true
                    },
                },
            },
            – Whitelist Facebook Apps
            LSApplicationQueriesSchemes =
            {
                “fb”,
                “fbapixxxx”,
                “fbapixxxx”,
        “fbapixxxx”,  --fb
        “fbapixxxx”,  --fb
        “fbapixxxx”,  --fb
                “fbapixxxx”,
                “fbapixxxx”,
                “fbapixxxx”,
                “fbapixxxx”,
                “fbauth”,
                “fbauth2”,
                “fb-messenger-apixxxx”
            },
        UIBackgroundModes = {“remote-notification”},
            UIAppFonts = {
        “Gabriola.ttf”,
                “Chivo-BlackItalic.ttf”,
                “ErasITC-Medium.ttf”,
        “KottaOne-Regular.ttf”,
                “LithosPro-Black.ttf”,
        “SegoePrint.ttf”,
        “PoetsenOne-Regular.ttf”,
                “Georgia.ttf”,
                “Quivira.ttf”,
                “Punjabi.ttf”,
                “Noto Sans Myanmar.ttf”,
                “Norasi.ttf”,
                “Loma.ttf”,
                “Lohit Telugu.ttf”,
                “Lohit Nepali.ttf”,
                “Lohit Odia.ttf”,
                “Lohit Tamil.ttf”,
                “Lohit Marathi.ttf”,
                “Lohit Devanagari.ttf”,
                “Lohit Bengali.ttf”,
                “Kruti Dev 730.ttf”,
                “Kinnari.ttf”,
                “Garuda.ttf”,
                “Casy EA.ttf”,
                “Braila.ttf”,
                “AGNI.ttf”
            },
            CFBundleIconFiles = {
                “Icon.png”,
                “Icon@2x.png”,
                “Icon-Small-40.png”,
                “Icon-Small-40@2x.png”,
                “Icon-Small-40@3x.png”,
                “Icon-120.png”,
                “Icon-152.png”,
                “Icon-60.png”,
                “Icon-60@2x.png”,
                “Icon-60@3x.png”,
                “Icon-72.png”,
                “Icon-72@2x.png”,
                “Icon-76.png”,
                “Icon-76@2x.png”,
                “Icon-Small-50.png”,
                “Icon-Small-50@2x.png”,
                “Icon-Small.png”,
                “Icon-Small@2x.png”,
                “Icon-Small@3x.png”
            },
        },
    },
    window = {
    defaultMode = “fullscreen”,
    defaultViewWidth = 1920,
    defaultViewHeight = 1080,
    resizeable = true,
    minViewWidth = 320,
    minViewHeight = 480,
    enableCloseButton = true,
    enableMinimizeButton = true,
    enableMaximizeButton = true,
    suspendWhenMinimized = true,
    titleText = {
        default = “xxxx”,
        
    },
    },
    osx =
    {
    budleResourcesDirectory = “osx-resources”,
    entitlements = {
        [“com.apple.security.personal-information.location”]=true,
    },
    plist = {
        NSHumanReadableCopyright = “Copyright 2016 by xxxx, Inc.”,
        ITSAppUsesNonExemptEncryption=false
    },
    }
}
 

I’d say that’s the problem.  Cider (or Glider) is presumably intercepting errors in some way.  Remove the require, run your app directly in the Corona Simulator and you should see your errors as expected (I just tried a test in a WebView listener so I’m confident it works in normal circumstances).

If that works then you should file a bug with Glider since it’s obviously not desirable for it to suppress errors.

Ah, this is good to know. Seems to be limited to the web listener.

Dear developers! When I was choosing from the many options it is your product, I have not seen any description not like:

  1. You can only write the application offline as any work with the network application proposes.

  2. All application and all timers are carried in one stream

  3. We do not provide technical support to users

It was not written in your advertising …

So why is this so?

Hi @execom.

I’m not sure I understand all your questions, but I’ll try and answer.

  1. With Corona SDK, until you either a) need a plugin, b) need to build for a device or deployment or c) try to access networking functions, you can use Corona SDK offline. But once you need something that requires network access, you are going to have to have network access.  You can either be online or offline while you work on your app depending on the above conditions. If you were to purchase Corona Enterprise, you could do everything off line with the exception of when your app needs networking.

  2. Corona SDK does run on one thread for most things. Somethings like audio I believe run on their own threads. However, Lua does support co-routines which are thread-like.  See: https://coronalabs.com/blog/2015/02/10/tutorial-using-coroutines-in-corona/ 

Many time consuming processes like network.request() use call back listeners which allows the main thread to continue running while it awaits completion in which the main thread picks back up with the call back listener.

  1. Corona Labs provides several layers of support. The first layer is here in the forums. The community is a great resource to figure out almost all the things you need. Staff members, like myself patrol the forums to answer product specific questions and things that may be bugs to determine if you should file a bug report or not. Our community members are really good this part too. We have probably the best community of developers on the Internet!  If you are not finding the help here that you need, we do offer a paid layer of support as well.  To say that we don’t offer technical support is incorrect. We have two developer relations specialists who check the forums multiple times seven days a week including holidays. Our engineering staff even steps in from time to time to directly answer questions. Oh, we also have an IRC channel too.

What leads you to believe that we don’t offer technical support to users?

As far as the game goes, I downloaded it and really didn’t notice any delays. But without seeing your network request code and the code calling your network request, it’s going to be hard to answer you.

BTW: Once a fish hits the bait, how do you real it in?

I am sorry for my second post. I did not know how to answer.

The problem is that the game has a chat, which is once every 6 seconds gets the current line of the room, I do it like this:

http\_headers = {} http\_headers ["Content-Type"] = "application / x-www-form-urlencoded" http\_headers ["Accept-Language"] = "en-US" http\_params = {} http\_params.headers = headers http\_params.timeout = 1 network.request (url, "GET", listenerChat, http\_params)

despite the fact that obviously limits the time 1 second, if the device bad ping request could hinder the execution to ANR

I have to once every 30 seconds to make the change ping, and if it is worse than I do the necessary suspension of all network requests. But in the process of measuring the ping again I come across lags. I get Ping follows:

true\_ping = true --global local old\_tick = system.getTimer() --this code is main.lua local resp\_check = function(event) local ping = system.getTimer() - old\_tick true\_ping = (not event.isError &nbsp;and &nbsp;event.status == 200 and ping \< 500) --quality ping end local req\_ping = function() network.request(host, 'POST', resp\_check, http\_params ) end local check\_ping = function(event) old\_tick = system.getTimer()--start point req\_ping() end timer.performWithDelay( 30000, check\_ping, 0 )--init timer ping req\_ping()--first tick

Apparently, there is a serious bug in Corona handling network request events. How can I be so sure? Check this out…

My app sends a network request to get the game player data of players in a multiplayer game --> and it does this once per second.

When the data comes into my Network Listener, it processes it by sorting it in a manner suitable for display. During my test, I’m sorting just 3 gamers - so it should finish in a handful of milleseconds. My point here is that it doesn’t take a full second and cause a timing issue. Once the code runs, I then run a timer to execute another network request. In this way, I’m always polling the multiplayer game data from the server.

Problem is, the code does not always reach the bottom of the listener. And it’s not because of another event. It simply just doesn’t. However, If I put a one-second delay on the next network request and place it at the start of my network listener code, it works perfectly. So, I can continue on developing my game. However, there is still no answer as to why the code does not always reach the bottom of my network listener.

Is there anything documented anywhere that would cause this to occur? I am experiencing this in the Mac OS Simulator. Is it isolated to the simulator?

What does your network listener function look like?

Does it always not make it to the same place of is the point where it stops variable?

Rob

I found that on the Mac Simulator, syntax errors are not caught in the web listener, such as:

print (string(a))  – this should have been print (tostring(aa))

and

if a==5 then   – if a==nil, no error is shown - code just stops in the listener and it does not continue

This is a real problem in the Mac Simulator, because I am confounded to discover run-time errors on iOS or Android that could have been avoided. Currently, I’m on my own to make sure there are no errors in my code and cannot rely on the Mac simulator.

I just dropped:  print (string(a))

Into a function that’s handling the call back from a network request and it blew up with this error:
 

ERROR: Runtime error /Volumes/Macintosh HD/Media/Projects/CoronaSDK/CoronaWeather/currentConditions.lua:268: attempt to call global 'string' (a table value) stack traceback: [C]: in function 'string' /Volumes/Macintosh HD/Media/Projects/CoronaSDK/CoronaWeather/currentConditions.lua:268: in function \</Volumes/Macintosh HD/Media/Projects/CoronaSDK/CoronaWeather/currentConditions.lua:264\>

Can you post your build.settings?

Have you done something to turn off error trapping?

Are you using a global variable called “debug”

Rob