Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
how to set the timeout for the socket? — Gideros Forum

how to set the timeout for the socket?

OZAppsOZApps Guru
edited January 2013 in General questions
there is a
settimeout
function for the
socket.tcp
portion of things, how do you set the timeout for the socket object? specially since it is blocking and when you use
connect
and the host is unavailable?
twitter: @ozapps | http://www.oz-apps.com | http://howto.oz-apps.com | http://reviewme.oz-apps.com
Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
Cool Vizify Profile at https://www.vizify.com/oz-apps

Comments

  • @OZApps not really get what you mean by socket object, but something from this might help
    http://appcodingeasy.com/Gideros-Mobile/Using-LuaSocket-in-Gideros

    With connecting I dunno if it would change anything if you set timeout before connecting?
  • if you were to use
    socket.connect("nonexistanthost", 80)
    since the code is blocking, it might never return for a host that it cannot reach. The timeout setting can be set when using the socket.tcp functions for a server/client type setting.

    So if you have
    socket.connect("www.gideromobile.com", 80)
    and
    socket.connect("not.valid.com",80)
    the first part will return but the connection to the not.valid would take an arbitrary time before it returns (if it does).
    twitter: @ozapps | http://www.oz-apps.com | http://howto.oz-apps.com | http://reviewme.oz-apps.com
    Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
    Cool Vizify Profile at https://www.vizify.com/oz-apps
  • ar2rsawseenar2rsawseen Maintainer
    edited January 2013 Accepted Answer
    socket.connect is basically a shorthand for creating a TCP client object connected to a remote host.

    So maybe not using a shorthand could help as:
    --first create tcp instance
    local tcp = socket.tcp()
     
    --set time out
    tcp:settimeout(0)
     
    --then connect it to server
    tcp:connect("nonexistanthost", 80)
    But haven't tried that
  • thanks, but it did not work for me.
    twitter: @ozapps | http://www.oz-apps.com | http://howto.oz-apps.com | http://reviewme.oz-apps.com
    Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
    Cool Vizify Profile at https://www.vizify.com/oz-apps
  • BJGBJG Member
    edited January 2013 Accepted Answer
  • It did not work for me earlier as I was not considering it with the tcp communication and relying on the returned handle. The timeout works perfectly fine now.
    twitter: @ozapps | http://www.oz-apps.com | http://howto.oz-apps.com | http://reviewme.oz-apps.com
    Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
    Cool Vizify Profile at https://www.vizify.com/oz-apps
Sign In or Register to comment.