Connect To Server At Startup

The place to discuss anything and everything about running your LiveCode on Android

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Googie85
Posts: 199
Joined: Tue Aug 05, 2014 10:07 am

Connect To Server At Startup

Post by Googie85 » Sun Jan 14, 2018 9:13 am

I am trying to get a loop that continues to connect to a server and creates the loop until it can connect to the said server. Once connected it puts a "1" into the "Count" variable and then exits the loop. Do you guys have any ideas on what im doing or a different way to go about this?

Many Thanks!!

Googie.


Code: Select all

on openStack
   open socket "192.168.15.189:12345" with message "CONNECTED"
   if Count = 1 then break else
   wait 5 seconds
   open socket "192.168.15.189:12345" with message "CONNECTED"

         if Count = 1 then break else
   wait 5 seconds
   open socket "192.168.15.189:12345" with message "CONNECTED"

      if Count = 1 then break else
   wait 5 seconds
   open socket "192.168.15.189:12345" with message "CONNECTED"

      if Count = 1 then break else
   wait 5 seconds
   open socket "192.168.15.189:12345" with message "CONNECTED"

      if Count = 1 then break else
   wait 5 seconds
end openStack

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Connect To Server At Startup

Post by Mark » Sun Jan 14, 2018 2:25 pm

The syntax "wait 5 seconds" is blocking and during this time LiveCode will never be able to make a connection. Instead, you should use "wait 5 seconds with messages" but there is a better way to do this.

Code: Select all

local lSock = "192.168.15.189:12345"

on openStack
  newConnection
end openStack

on newConnection
  if lSock is not among the lines of the openSockets then
    open socket lSock with message "connected"
    send "newConnection" to me in 5 seconds
  end if
end newConnection
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Post Reply

Return to “Android Deployment”