# this example illustrates the use of a task to establish a connection # by perioidic retries. when the connection succeeds, the stream # object is stored in the 'connections' list. # start the script as: # # pf tcp-retry-connect.pf load-scheduler () variable! connections variable server : spawn-retry-connect 2 fork # give 2 arguments to the task server local-variable # 'server' is a local variable 2 list server ! # store server address and port begin # keep trying till we have a connection try server @ "w" open-connect # attempt to connect connections push # connect succeeded finish # work done, this kills the task recover # connect failed drop # we know what the error is: discard 1000. sleep # wait a while "RETRY" p cr endtry again ; ; "( host port -- )\tTry to connect to host:port." doc : next-arg args pop ; next-arg drop # discard script name next-arg # get host (keep it as a string) next-arg interpret-string # get port (interpret the string -> number) spawn-retry-connect # start the retry task # ("asdfasdf.net" 123) interactive