Monitor UDP broadcasts from 4D ServerKeisuke Miyako (5/30/14 3:08AM)
Keisuke Miyako (5/30/14 3:48AM)
Keisuke Miyako (5/30/14 3:08 AM)
as explained in the 4D Internet Commands documentation,
it is possible to listen to 4D Server publishing its name over the
which is fine if you want 4D to watch if a 4D Server is running,
but you might argue that actually it makes more sense that an
application /other than/ 4D should do that job.
so here I posted a small command-line program that does the same thing.
it comes with an AppleScript example.
if you prefer to write a shell script then by all means go ahead.
a built 4D Remote can connect to its server based on its internal
normally you build the client without a 4dlink file,
run it for the first time on the deployment network,
and select the server.
the IP address will be recorded in the 4dlink file,
so from the next time,
it will automatically connect to the server,
as long as the location doesn?=A2?=82¨=E2Ñ¢t change.
now, suppose you have a mirror server on the same network.
obviously its IP address is different from that of the main server.
if the main server becomes unavailable,
then the next time a client is launched it will attempt to connect to
the dead server for about a minute,
then eventually display a "runtime error" dialog that the "process has
runtime errors shown to the end user is never a good thing.
first, the phrase ?=A2?=82¨=C5ìerror?=A2?=82¨=C2ù is
and the error message almost always impenetrable (?=A2?=82¨=C5ìpro
aborted?=A2?=82¨=C2ù what does that even mean?)
so I am working with a customer,
to setup a mirror system where the IP address of the mirror and main
automatically switches if the main goes down.
the end user will launch the client first thing in the morning and not
even know that it has connected to a mirror.
the mirror will send a notification to the developer if it accepts a
but at least it will buy some time to restore the main by say, lunch
its is still just a proof of concept for this particular customer,
but the command like tool is generic so I?=A2?=82¨=E2Ñ¢ve
released it on GitHub.
the code is almost generic C but requires some modification to compile
(especially the part the converts the UDP packet to Unicode)
Keisuke Miyako (5/30/14 3:48 AM)
slightly off topic but on the subject of ?=A2?=82¨=C5ìsingle
I've been forced to learn that AppleScript is single threaded,
and that an application written in AS should be coded accordingly.
So what does it mean to code ?=A2?=82¨=C5ìsingle threaded?=A2?
My very short answer would be, ?=A2?=82¨=C5ìdon?=A2?=82¨=E2Ñ
¢t run in a large infinite
bad example in AppleScript is a single "Repeat~End repeat?=A2?=82¨=C2
ù that goes
bad example in 4D is a Repeat~MODIFY SELECTION~Until(OK=0) written in
or a long loop inside an object method.
maybe programmers coming from a C background where the main() is the
application entry point,
tends to code their application like a single infinite loop,
but that style is not really suited for a single threaded
instead, in AppleScript,
the correct way to code an application is to not run any code in the
define event handlers,
like On run, On Idle, On Exit.
4D is also event driven,
so it is better to passively process events dispatched by the runtime,
rather than to code as if you are writing the main application
It is therefore very important to be familiar with the full range of
and not abuse them.
As Josh mentioned in another thread,
if an event is called ?=A2?=82¨=C5ìOn Web Authentication?=A2?=82
then it should only do what is it supposed to do during that phase,
and not go off in a tangent and do all sorts of other things.
form events can be quite tolerant,
but database events, such as
On Startup, On Exit, COMPILER_WEB, SOAP/WEB/REST/SQL connections and
should aim to run code that is simple and/or quick,
in order not to block the main application.
Reply to this message
Summary created 5/30/14 at 9:17AM by Intellex Corporation
Comments welcome at: email@example.com