summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorArtyom Poptsov <poptsov.artyom@gmail.com>2014-01-07 17:50:43 +0400
committerArtyom Poptsov <poptsov.artyom@gmail.com>2014-01-07 17:50:43 +0400
commitbb1ea0987c3ecec5a6da10616bf6b8b43b1a294f (patch)
tree4e4a929b9e334e0b56572b3d473e0a3ca472549a /examples
parentchannel-{func,type}.c, channel.scm: Update documentation. (diff)
downloadguile-ssh-bb1ea0987c3ecec5a6da10616bf6b8b43b1a294f.tar.gz
examples/echo/{client,server}.scm: Update.
* examples/echo/server.scm (read-all): New procedure. (main): Update. Catch exceptions. Use `write-line' instead of `display'. * examples/echo/client.scm (read-all): New procedure. (main): Update. Use `char-ready?' instead of `channel-poll'. Use `write-line' instead of `display'.
Diffstat (limited to 'examples')
-rwxr-xr-xexamples/echo/client.scm28
-rwxr-xr-xexamples/echo/server.scm21
2 files changed, 33 insertions, 16 deletions
diff --git a/examples/echo/client.scm b/examples/echo/client.scm
index ccbc9bb..bb52105 100755
--- a/examples/echo/client.scm
+++ b/examples/echo/client.scm
@@ -80,6 +80,14 @@
(handle-error session))
pubkey))
+(define (read-all port)
+ "Read all lines from the PORT."
+ (let r ((res "")
+ (str (read-line port 'concat)))
+ (if (not (eof-object? str))
+ (r (string-append res str) (read-line port 'concat))
+ res)))
+
(define (main args)
"Entry point of the program."
@@ -96,8 +104,6 @@
(help-needed? (option-ref options 'help #f))
(args (option-ref options '() #f)))
-
-
(if help-needed?
(begin
(print-help)
@@ -116,6 +122,7 @@
#:log-verbosity 0))) ;Be quiet
(connect! session)
+
(case (authenticate-server session)
((not-known) (display " The server is unknown. Please check MD5.\n")))
@@ -125,23 +132,20 @@
(if (eqv? (userauth-pubkey! session #f public-key private-key) 'error)
(handle-error session))
- (let ((channel (make-channel session)))
+ (let ((channel (make-channel session)))
(if (not channel)
(handle-error session))
(channel-open-session channel)
- (display str channel)
+ (write-line str channel)
- (let poll ((count #f))
- (if (or (not count) (zero? count))
- (poll (channel-poll channel #f))
- (begin
- (display (read-line channel))
- (newline))))
+ (let poll ((ready? #f))
+ (if ready?
+ (format #t "Response from server: ~a~%" (read-all channel))
+ (poll (char-ready? channel))))
- (close channel)
- (display channel))))))
+ (close channel))))))
;;; echo.scm ends here.
diff --git a/examples/echo/server.scm b/examples/echo/server.scm
index 8aa07b7..8016ea4 100755
--- a/examples/echo/server.scm
+++ b/examples/echo/server.scm
@@ -81,6 +81,14 @@
(else
(message-reply-success msg)))))
+(define (read-all port)
+ "Read all lines from the PORT."
+ (let r ((res "")
+ (str (read-line port 'concat)))
+ (if (and (not (eof-object? str)) (char-ready? port))
+ (r (string-append res str) (read-line port 'concat))
+ res)))
+
(define (main args)
(let ((server (make-server #:bindport *default-bindport*
#:rsakey *default-rsakey*
@@ -122,10 +130,15 @@
(set! channel (handle-req-channel-open msg msg-type))
(let poll ((ready? #f))
(if ready?
- (let ((str (read-line channel)))
- (format #t "Received message: ~a~%" str)
- (display "Echoing back...\n")
- (display str channel))
+ (catch 'guile-ssh-error
+ (lambda ()
+ (let ((str (read-all channel)))
+ (format #t "Received message: ~a~%" str)
+ (display "Echoing back...\n")
+ (write-line str channel)))
+ (lambda (key . args)
+ (display "error\n")
+ (display (get-error session))))
(poll (char-ready? channel))))
(close channel))