' Collection of code snippets by Arne Vajhøj 
' (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) 
program p8

option type = explicit

declare integer constant port = 12345
declare string constant host = "localhost"

declare integer sd, msglen
declare string outmsg
map (inmsg) string inmsg = 1000

external integer function vms_socket_open(string, integer)
external sub vms_socket_send(integer, string)
external integer function vms_socket_recv(integer, string, integer)
external sub vms_socket_close(integer)

! open connection
sd = vms_socket_open(host, port)
! send message
outmsg = "Hi from Basic!"
call vms_socket_send(sd, outmsg)
! receive all messages
while vms_socket_recv(sd, inmsg, msglen)
   print "|" + mid(inmsg, 1, msglen) + "|"
next
! close connction
call vms_socket_close(sd)

end program
