Created
September 25, 2013 09:58
-
-
Save Gonzih/6697519 to your computer and use it in GitHub Desktop.
cl-async socket test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#-quicklisp | |
(let ((quicklisp-init (merge-pathnames "quicklisp/setup.lisp" | |
(user-homedir-pathname)))) | |
(when (probe-file quicklisp-init) | |
(load quicklisp-init))) | |
(ql:quickload "cl-async") | |
(defun error-handler () | |
(lambda (err) (format t "listener event: ~a~%" err))) | |
(defun my-echo-server () | |
(format t "Starting server.~%") | |
(as:tcp-server "0.0.0.0" 9003 | |
(lambda (socket data) | |
;; echo the data back into the socket | |
(format t "Data received to socket: ~a~%" data) | |
(as:write-socket-data socket data)) | |
#'error-handler) | |
;; catch sigint | |
(as:signal-handler 2 (lambda (sig) | |
(declare (ignore sig)) | |
(as:exit-event-loop)))) | |
(defun send-data () | |
(format t "Sending data~%") | |
(let ((stream (as:tcp-connect "0.0.0.0" 9003 | |
(lambda (socket data) | |
(format t "Received data from server ~a~%" data)) | |
#'error-handler | |
:stream t))) | |
(loop for i from 1 to 100 | |
do (progn | |
(write-sequence (format nil "~a~%" i) stream))))) | |
(defun run () | |
(my-echo-server) | |
(send-data)) | |
(as:start-event-loop #'run) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Starting server. | |
Sending data | |
Data received to socket: #(49 10 50 10 51 10 52 10 53 10 54 10 55 10 56 10 57 | |
10 49 48 10 49 49 10 49 50 10 49 51 10 49 52 10 49 | |
53 10 49 54 10 49 55 10 49 56 10 49 57 10 50 48 10 | |
50 49 10 50 50 10 50 51 10 50 52 10 50 53 10 50 54 | |
10 50 55 10 50 56 10 50 57 10 51 48 10 51 49 10 51 | |
50 10 51 51 10 51 52 10 51 53 10 51 54 10 51 55 10 | |
51 56 10 51 57 10 52 48 10 52 49 10 52 50 10 52 51 | |
10 52 52 10 52 53 10 52 54 10 52 55 10 52 56 10 52 | |
57 10 53 48 10 53 49 10 53 50 10 53 51 10 53 52 10 | |
53 53 10 53 54 10 53 55 10 53 56 10 53 57 10 54 48 | |
10 54 49 10 54 50 10 54 51 10 54 52 10 54 53 10 54 | |
54 10 54 55 10 54 56 10 54 57 10 55 48 10 55 49 10 | |
55 50 10 55 51 10 55 52 10 55 53 10 55 54 10 55 55 | |
10 55 56 10 55 57 10 56 48 10 56 49 10 56 50 10 56 | |
51 10 56 52 10 56 53 10 56 54 10 56 55 10 56 56 10 | |
56 57 10 57 48 10 57 49 10 57 50 10 57 51 10 57 52 | |
10 57 53 10 57 54 10 57 55 10 57 56 10 57 57 10 49 | |
48 48 10) | |
Received data from server #<ASYNC-IO-STREAM {100652D743}> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment