Test the internet connection like "Designer City"

I was looking at the crown success stories, so I tried: “Designer City”.

So I downloaded the game. This is really fantastic!! There are so many things I like.

One thing left me stunned above all and for this I ask the question.

The connection in real time very fluid.

I’m trying to play a game with some areas that require constant connection.

So I wondered if it was possible to know how to check the connection almost every second without a drop in performance.

Before writing this question I did research on corona. I found several conection checks, but nothing so high for what I need…

Is there a question in there?  A specific question. :slight_smile:

i.e. Are you asking SGS to show you how he does it?

Also, have you tested the various solutions you’ve seen and examined their impact? That is, how have you determined they are not suitable.

A typical ping or socket check is pretty fast.

Finally, every second?  That seems wasteful.

You can tell if you’ve lost connection simply by trying to communicate with your endpoint.

I think you should elaborate on how you want to use this.  Give us the larger picture.

@sgs - Do you actually test your internet connection once per second or even at all beyond initial check?

I am guessing you do not, but rely on other techniques to know if you’re connected or having a problem talking to the sever.

@roaminggamer thank you and sorry if I misunderstood the question

I’m not asking directly to @sgs. I’d like an answer from him but I do not know if he can share some of his code so I “asked to everyone”.

In my game I often ask for database rankings and I share things between users.

At the moment I have set some code in every network request that shows an error text if the request fails…

But it is a bit boring to do this for every request, I also have to wait for the negative answer or check the connection every time first.

So I thought to create a graphic signal that indicates in real time if it is connected or not (example attached).

So I would save a global flag(bool)  indicating whether or not there is conection

My current code is something like this:

internetConnection = false local function checksInternetConnection() local socket = require("socket") local test = socket.tcp() test:settimeout(1, 't') -- Set timeout to 1 second local testResult = test:connect("www.google.com", 80) local thereIs if not(testResult == nil) then thereIs = true else thereIs = false end test:close() test = nil internetConnection = thereIs end timer.performWithDelay( 1000, checksInternetConnection, -1 )

One thing that would be cooler is to track average turnaround time for requests.

You can do this easily.  

  1. Every time you make a request, note the start time in a unified tracking table.  

  2. Have the listener calculate the round-trip time.

  3. Add that to an total for all requests (over a limited period) and divide by all requests in that period.

Now, you can make a sweet looking graphic with a wheel graph or other look showing average latency as a percentage of some standard value or a number itself.  Go nuts with it.

You can also add a indicator to show a generic error status.

If you make a purchase I’ll tell you my secrets!  :wink:

Actually, I test every 30s which is fine for my purpose.

The method you propose is wasteful as you will be incurring a data charge for the user on every check.  We are lucky that data is cheap for us but in other countries this is not the case.  Also pinging Google that often will just get you blocked by their DoS.

So I check for a valid “physical” connection but not whether data can actually be sent.  This is 99% good enough, costs nothing and means I don’t pointlessly try and do network requests.  It is so fast it could check every second - but why bother?

I allow online and offline play, the game just adapts.

@roaminggamer

What you said is not exactly what I needed but it is a great idea that I could integrate!

@SGS

I do not like completing games by paying. But I like helping people who do great things,(and a boost in the game never hurts). So why not :wink:

Anyway I thank you for your tips. I thought to check for a valid “physical”, but I have not found any API that allows this (iOS and Android). In my research I came across “network.getConnectionStatus()”  but I have seen many discouraged.

you do not use that, right? I hope I’m not asking for too personal things…

I use undocumented APIs but that is obviously subject to breaking at any time… 

Is there a question in there?  A specific question. :slight_smile:

i.e. Are you asking SGS to show you how he does it?

Also, have you tested the various solutions you’ve seen and examined their impact? That is, how have you determined they are not suitable.

A typical ping or socket check is pretty fast.

Finally, every second?  That seems wasteful.

You can tell if you’ve lost connection simply by trying to communicate with your endpoint.

I think you should elaborate on how you want to use this.  Give us the larger picture.

@sgs - Do you actually test your internet connection once per second or even at all beyond initial check?

I am guessing you do not, but rely on other techniques to know if you’re connected or having a problem talking to the sever.

@roaminggamer thank you and sorry if I misunderstood the question

I’m not asking directly to @sgs. I’d like an answer from him but I do not know if he can share some of his code so I “asked to everyone”.

In my game I often ask for database rankings and I share things between users.

At the moment I have set some code in every network request that shows an error text if the request fails…

But it is a bit boring to do this for every request, I also have to wait for the negative answer or check the connection every time first.

So I thought to create a graphic signal that indicates in real time if it is connected or not (example attached).

So I would save a global flag(bool)  indicating whether or not there is conection

My current code is something like this:

internetConnection = false local function checksInternetConnection() local socket = require("socket") local test = socket.tcp() test:settimeout(1, 't') -- Set timeout to 1 second local testResult = test:connect("www.google.com", 80) local thereIs if not(testResult == nil) then thereIs = true else thereIs = false end test:close() test = nil internetConnection = thereIs end timer.performWithDelay( 1000, checksInternetConnection, -1 )

One thing that would be cooler is to track average turnaround time for requests.

You can do this easily.  

  1. Every time you make a request, note the start time in a unified tracking table.  

  2. Have the listener calculate the round-trip time.

  3. Add that to an total for all requests (over a limited period) and divide by all requests in that period.

Now, you can make a sweet looking graphic with a wheel graph or other look showing average latency as a percentage of some standard value or a number itself.  Go nuts with it.

You can also add a indicator to show a generic error status.

If you make a purchase I’ll tell you my secrets!  :wink:

Actually, I test every 30s which is fine for my purpose.

The method you propose is wasteful as you will be incurring a data charge for the user on every check.  We are lucky that data is cheap for us but in other countries this is not the case.  Also pinging Google that often will just get you blocked by their DoS.

So I check for a valid “physical” connection but not whether data can actually be sent.  This is 99% good enough, costs nothing and means I don’t pointlessly try and do network requests.  It is so fast it could check every second - but why bother?

I allow online and offline play, the game just adapts.

@roaminggamer

What you said is not exactly what I needed but it is a great idea that I could integrate!

@SGS

I do not like completing games by paying. But I like helping people who do great things,(and a boost in the game never hurts). So why not :wink:

Anyway I thank you for your tips. I thought to check for a valid “physical”, but I have not found any API that allows this (iOS and Android). In my research I came across “network.getConnectionStatus()”  but I have seen many discouraged.

you do not use that, right? I hope I’m not asking for too personal things…

I use undocumented APIs but that is obviously subject to breaking at any time…