Call

Advanced
Aptilis 1

Call(IP[:port], SubName [, paramList])

Call allows you to call a sub in another aptilis program that may be running on the same machine or even on a different machine on your Intranet, or on the Internet.

The first parameter is the IP number of the machine you want to talk to. It may be a fully qulaified domain such as:
machine.domain.co.cc, for example aptilis-newx.cnn.com (imaginary!)
You can also specify a port as in:
aptilis-newx.cnn.com:63.

The second parameter is the sub name, ie. the sub you want to call (if it's in a program you haven't written, you have to have been given its name and the parameters it takes). You can have up to 32 parameters in call so that leaves you 30 to pass over.
You are limited to 30 parameters (which should be quite enough in most cases, actually) but since you can pass arrays, there is virtually no limit to the amount of information that can be passed.

Return value:
The value returned by the called sub or -1 in case of error, in which case the _errno variable will contain more details.

Example:
This is a complete example of a 'Talk' program written in aptilis.
This program is a variation of another program that I used to demonstrate the same thing, but here I added the 'input' in the 'RDspl()' sub. That makes the program, a one-way, one to one communication device, a bit like the CB radio, where two people talk in turn.
If you remove the input in the 'RDspl()' sub, you will then need to have two windows open, one to listen, the other one to talk.
To use this program, use a DOS box (NT/95-98) or a shell and run the eqxTalk.e.txt program. Select 'L' for listening. The person you want to talk with needs to do the same thing, but will have to select 'T' instead, and then enter your IP number. He/She will have to initiate the dialog. You will then reply and so on.

sub main


print("Which end? (L)isten or (T)alk?\n")
m = upper(trim(input(4)$)$)$

if m = "L" $
TakeCalls(1)
print("Program stopped\n")
end if

if m = "T" $
Chat()
end if

print("Thank You. Ba-bye\n")

end sub


sub Chat()

print("Who are you talking to?")
ip = trim(input(80) $) $


repeat
m = input(4000) $

r = call(ip$, "RDspl", m$) $
if r = -1
print("errno = ", _errno$, "\n")
else
print(r$, "\n")
end if
m = trim(lower(m$)$)$
until m = "bye" $



end Chat



sub RDspl(ip, message)

print("[", ip$, "]: ", message$, "\n")
reply = input(80) $

if trim(message$) = "kill" $
takeCalls(0)
print("Now Leaving...\n")
end if

return reply$

end RDspl
For more details, see the Remote Sub Invocation topic.