overriding the port from network.request() api

My backend is build on Google App Engine…App engine runs locally (on my mac) at port 8080

App engine won’t easily bind to port 80

But I can (and have) forwarded all port 80 traffic to 8080

I have tested the forwarding from both the browser and terminal

Even inside the corona simulator, network.setStatusListener tells me “true” (meaning the server address [hostmac.com] is reachable)

However, whenever I try to make network.request (from inside corona simulator) to the server, I get:

Corona Simulator[57220:507] recent net-reachability status for “hostmac.com” was true

Corona Simulator[57220:507] ERROR: Error during request, code: -1002, details: unsupported URL

Corona Simulator[57220:507] Network error occured in original WS call!  nil

Corona Simulator[57220:507] table: 0x7fad2d76dbf0 {

[“phase”]=“ended”

[“bytesTransferred”]=0

[“name”]=“networkRequest”

[“isError”]=true

[“status”]=-1

[“url”]=“hostmac.com/user/create

[“bytesEstimated”]=0

[“requestId”]=userdata: 0x7fad2d73f978}

 

All but one (#2) of the above error messages are my own debugging output.

That final table is the event-record received by my listener/callback function passed to network.request

 

Can anyone tell me whats going wrong here??

As a final note, if network.request DOES NOT allow you to override the port (other than 80) in the URL, that should be noted in the docs and its not.  I suspected that was the problem and went to all this trouble to forward port 80 and I’m pretty frustrated that it’s still not working

have you tried using the URL   http://mysite.com:8080/path/to/script

???

Rob

Yes I have & that’s what was not working Your answer implies (wish u would say directly) that Overriding the port IS OFFICIALLY SUPPORTED What SHOULD work with network.request? What about localhost? What about domains with no 1st level suffix? eg hostmac vs hostmac.com Thx D

I don’t have these answers for you.  I’ve never heard that we don’t support additional ports.  I’m pretty sure that I’ve seen people use localhost.  As far as non-fully qualified domain names, I would hope that wouldn’t do anything strange and not send the value directly to DNS. 

So I decided to do a test.  I don’t have a server running on any port other than 80 on my MacBook Pro, so I installed a node.js server and started it up on port 8080 that just print’s “Hello World” on any request.  Using this code:

local function networkListener( event )         if ( event.isError ) then                 print( "Network error!")         else                 print ( "RESPONSE: " .. event.response )         end end -- Access Google over SSL: network.request( "http://localhost:8080/", "GET", networkListener )

I got the following in my terminal window (using the simulator)

Copyright © 2009-2014  C o r o n a   L a b s   I n c .
2014-05-17 20:53:36.857 Corona Simulator[3210:507]     Version: 3.0.0
2014-05-17 20:53:36.858 Corona Simulator[3210:507]     Build: 2014.2306
2014-05-17 20:53:36.871 Corona Simulator[3210:507] Platform: iPhone / x86_64 / 10.9 / Intel HD Graphics 4000 OpenGL Engine / 2.1 INTEL-8.24.12
2014-05-17 20:53:36.944 Corona Simulator[3210:507] The file sandbox for this project is located at the following folder:
    (/Users/rmiracle/Library/Application Support/Corona Simulator/tmp-292D2A5488D376935C88DB31A32368A3)
2014-05-17 20:53:37.264 Corona Simulator[3210:507] RESPONSE: Hello World
2014-05-17 20:54:41.969 Corona Simulator[3210:507]

So from this test, at least on a Mac, running a valid server on port 8080 and using “localhost” as the host, it works as expected.  Now I did notice that when testing the server by telnet’ing to it I got a weird redirect error.  Apparently my /etc/hosts has a weird definition for localhost in it:

127.0.0.1    localhost
255.255.255.255    broadcasthost
::1             localhost
fe80::1%lo0    localhost

I don’t know what that ::1 is or where it came from, however telnet (and the Corona Simulator) was smart enough to fall back and get the real localhost at 127.0.0.1.   It’s quite possible you might have a network configuration error if you are trying to forward 80 to 8080 instead of accessing it directly.  Your /etc/hosts might be configured oddly. 

Rob

yep, looks like a problem with my hosts file

even after I disabled the port forwarding, it didn’t work until I switched hostmac.com back to localhost and then your test worked on my box…

humm…well glad it’s working…and thanks for your help

please add some docs to network.request that shows port overrides ARE supported because there are several posts in this forum that imply port 80 only and someone else is liable to mis-interpret that and go down the same useless rabbit hole I did…

thanks again

D

well this is interesting…

Last night, on my home Lan, I had everything working just fine

Today, I’m working via my AT&T hotspot from a public park, and localhost is not reachable again…

Perhaps it has something to do with that strange :1 bind to localhost in the hosts file??

Any tips?

Thx

D

Can I suggest just trying to open 127.0.0.1 instead of a name.  That’s about as clean a way to get to the internal network services.

Rob

This is crazy…I’m back home and localhost is not working again.

Yes, Rob, 127.0… is working fine…which allows me to move forward…a bit

But I really don’t like having a different pattern (digits vs string) between dev and production…it will be a PITA for testing because I have a reg-ex that removes the :8080 part (all driven by an app config file) for the isReachable code and now I need to handle both cases…

I wish someone could explain this to me…

I personally would not want to test against a server running on your local machine.  You’re customers will be using some online server and the sooner you get that setup the sooner you will get a feel for reality.

The networking code first looks to DNS (Domain Name Services) to try and convert a text name to an IP Address.  If that fails it falls back to the local hosts file.  Because most people don’t maintain their hosts file and that DNS could try and return something invalid, if you’re going to use the local machine, it’s better to go ahead and hard code that address.  If you’re going to use names, I would say go on line sooner than later.

Rob

I do have a remote server and have had for some time…I meant “developer” testing…not end user testing…it’s pretty cumbersome to be revising server code and pushing it constantly…in my experience, local is the only reasonable approach until the major architectural patterns are in place and substantial bugs resolved…and of course my user testing will be in the cloud.

Thanks for your thoughts and feedback…127.0 is working fine but localhost comes and goes like the wind…I can’t make sense of it yet…

D

I don’t see what the difference is.  You use a string, which can either be “localhost” or “127.0.0.1” or you have a string that is the DNS name of your server.  At some point you have to change your local name to your remote name, and if the name is just a string it shouldn’t matter what it is.

If you’re going to be changing it or not I would use something like:

local useLocalHost = true

local host = "http://myremoteserver.com"

if useLocalHost then

     host = “127.0.0.1”

end

Then just use the variable host in your code.  You can quickly toggle that flag on and off depending on where you want to test. 

have you tried using the URL   http://mysite.com:8080/path/to/script

???

Rob

Yes I have & that’s what was not working Your answer implies (wish u would say directly) that Overriding the port IS OFFICIALLY SUPPORTED What SHOULD work with network.request? What about localhost? What about domains with no 1st level suffix? eg hostmac vs hostmac.com Thx D

I don’t have these answers for you.  I’ve never heard that we don’t support additional ports.  I’m pretty sure that I’ve seen people use localhost.  As far as non-fully qualified domain names, I would hope that wouldn’t do anything strange and not send the value directly to DNS. 

So I decided to do a test.  I don’t have a server running on any port other than 80 on my MacBook Pro, so I installed a node.js server and started it up on port 8080 that just print’s “Hello World” on any request.  Using this code:

local function networkListener( event )         if ( event.isError ) then                 print( "Network error!")         else                 print ( "RESPONSE: " .. event.response )         end end -- Access Google over SSL: network.request( "http://localhost:8080/", "GET", networkListener )

I got the following in my terminal window (using the simulator)

Copyright © 2009-2014  C o r o n a   L a b s   I n c .
2014-05-17 20:53:36.857 Corona Simulator[3210:507]     Version: 3.0.0
2014-05-17 20:53:36.858 Corona Simulator[3210:507]     Build: 2014.2306
2014-05-17 20:53:36.871 Corona Simulator[3210:507] Platform: iPhone / x86_64 / 10.9 / Intel HD Graphics 4000 OpenGL Engine / 2.1 INTEL-8.24.12
2014-05-17 20:53:36.944 Corona Simulator[3210:507] The file sandbox for this project is located at the following folder:
    (/Users/rmiracle/Library/Application Support/Corona Simulator/tmp-292D2A5488D376935C88DB31A32368A3)
2014-05-17 20:53:37.264 Corona Simulator[3210:507] RESPONSE: Hello World
2014-05-17 20:54:41.969 Corona Simulator[3210:507]

So from this test, at least on a Mac, running a valid server on port 8080 and using “localhost” as the host, it works as expected.  Now I did notice that when testing the server by telnet’ing to it I got a weird redirect error.  Apparently my /etc/hosts has a weird definition for localhost in it:

127.0.0.1    localhost
255.255.255.255    broadcasthost
::1             localhost
fe80::1%lo0    localhost

I don’t know what that ::1 is or where it came from, however telnet (and the Corona Simulator) was smart enough to fall back and get the real localhost at 127.0.0.1.   It’s quite possible you might have a network configuration error if you are trying to forward 80 to 8080 instead of accessing it directly.  Your /etc/hosts might be configured oddly. 

Rob

yep, looks like a problem with my hosts file

even after I disabled the port forwarding, it didn’t work until I switched hostmac.com back to localhost and then your test worked on my box…

humm…well glad it’s working…and thanks for your help

please add some docs to network.request that shows port overrides ARE supported because there are several posts in this forum that imply port 80 only and someone else is liable to mis-interpret that and go down the same useless rabbit hole I did…

thanks again

D

well this is interesting…

Last night, on my home Lan, I had everything working just fine

Today, I’m working via my AT&T hotspot from a public park, and localhost is not reachable again…

Perhaps it has something to do with that strange :1 bind to localhost in the hosts file??

Any tips?

Thx

D

Can I suggest just trying to open 127.0.0.1 instead of a name.  That’s about as clean a way to get to the internal network services.

Rob

This is crazy…I’m back home and localhost is not working again.

Yes, Rob, 127.0… is working fine…which allows me to move forward…a bit

But I really don’t like having a different pattern (digits vs string) between dev and production…it will be a PITA for testing because I have a reg-ex that removes the :8080 part (all driven by an app config file) for the isReachable code and now I need to handle both cases…

I wish someone could explain this to me…

I personally would not want to test against a server running on your local machine.  You’re customers will be using some online server and the sooner you get that setup the sooner you will get a feel for reality.

The networking code first looks to DNS (Domain Name Services) to try and convert a text name to an IP Address.  If that fails it falls back to the local hosts file.  Because most people don’t maintain their hosts file and that DNS could try and return something invalid, if you’re going to use the local machine, it’s better to go ahead and hard code that address.  If you’re going to use names, I would say go on line sooner than later.

Rob

I do have a remote server and have had for some time…I meant “developer” testing…not end user testing…it’s pretty cumbersome to be revising server code and pushing it constantly…in my experience, local is the only reasonable approach until the major architectural patterns are in place and substantial bugs resolved…and of course my user testing will be in the cloud.

Thanks for your thoughts and feedback…127.0 is working fine but localhost comes and goes like the wind…I can’t make sense of it yet…

D