hi, I'm a newbie of newlisp. now I writed one very simple mud client as following.
now it has two problem:
1. if I use readline search function, the program will exit silently. I think it is about memory problem. can anyone fix it ???
2. when the peer of socket close the connection, the program will exit. but I must enter an "\n" before the console returned to shell. why ?
thanks.
this is the probram:
#!/usr/bin/newlisp
;; server
(define mud-server '("pkuxkx.3322.org" 8081))
(context 'greadline)
(import "libhistory.so.5" "add_history")
(import "libreadline.so.5" "readline")
(define (greadline:greadline)
(set 'getted-string-p (readline ""))
(add_history getted-string-p)
(get-string getted-string-p))
(context MAIN)
(set 'server (apply net-connect mud-server))
(fork (begin
(while (net-receive server buffer 8192)
(print buffer))
(letn ((error (net-error))
(error-code (error 0)))
(if (= error-code 6)
(println "bye bye!!")
(print (error 1))))))
(constant 'SIGCHLD 17)
(define (sig_chld_handler)
(wait-pid -1 nil)
(close server)
(exit))
(signal SIGCHLD sig_chld_handler)
(while 1 (net-send server (append (greadline) "\r\n")))
(exit)
a question about import. history library
For one thing, when you initialize with (readline ""), you are sending a string that is not anchored in memory. Assign "" to a local variable and then pass it to readline.
You exit early because you do (while (net-receive ...)). For an example on how to loop a socket server indefinitely, take a look at my sockets module:
http://static.artfulcode.net/newlisp/sockets.lsp.html
You exit early because you do (while (net-receive ...)). For an example on how to loop a socket server indefinitely, take a look at my sockets module:
http://static.artfulcode.net/newlisp/sockets.lsp.html