Initial commit of newLISP.
[newlisp.git] / examples / client
blob9c132e5c33733509a9958ab0903a8ce00db14b69
1 #!/usr/bin/newlisp
3 ;;  client for  client/server demo
4 ;;
5 ;;  USAGE: client hostName
6 ;;
7 ;; 'hostName' contains a string with the name or IP number
8 ;; of the computer running the server application
9 ;;
10 ;; The client prompts for input and sends it to the
11 ;; server which sends it back converted to uppercase
13 ;; The server has to be started first in a different
14 ;; terminal window or on a different computer.
16 ;; v 1.3
19 (define (net-client-receive socket , buf)
20   (net-receive socket 'buf 256)
21   (print "\n" buf "\ninput:")
22   (if (= buf "bye bye!") (exit))
23   (net-send socket (read-line)))
25 (define (client host-computer)
26   (set 'socket (net-connect host-computer 1111))
27   (if (not socket) 
28     (print "could not connect, is the server started?\n") 
29     (while true (net-client-receive socket))))
31 (if (not (main-args 2)) 
32   (begin 
33     (print "USAGE: client hostName\n")
34     (exit)))
36 (client (main-args 2))
37 (exit)