[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
a network client
From: |
Catonano |
Subject: |
a network client |
Date: |
Thu, 13 Dec 2018 09:17:56 +0100 |
I wrote a small server in Guile scheme
I used the command "nc" to test it
It seems to work
Then I wrote a small client in Guile
It doesn't work and I don't understand why
At the REPL:
scheme@(lsp-client)> (run-ping-test 11211)
This runs the client
The client is supposed to write a short string on the socket connected to
the server and then read the serverÅ› reply from the same socket
But instead nothing happens
It doesn't return the prompt and the server doesn't receive any string
I know this because the server displays the string it receives on the
terminal, when it receives it
and it this case it doesn't display anything
So I interrupt the client with CTRL-C (2 times as one time seems to not
sufifce)
^C^CERROR: In procedure scm-error:
User interrupt
Entering a new prompt. Type `,bt' for a backtrace or `,q' to continue.
scheme@(lsp-client) [1]> ,q
scheme@(lsp-client)>
at this point I quit Guile, like this
scheme@(lsp-client)> ,q
At this point the sever DOES display the short string on the terminal !!
It seems that the client writes the string on the socket only when I close
the Guile process
Now, this is the client:
(define* (client addrinfo #:key (request-port 11211))
(let ((port (connect-to-server addrinfo)))
(put-string port "hello")
(put-char port #\newline)
(force-output port)
(let ((line (read-line port)))
(display line)
)
)
)
Instead, with the following simplified version, the server receives the
string and "run-ping-test" returns a value and the prompt
(define* (client addrinfo #:key (request-port 11211))
(let ((port (connect-to-server addrinfo)))
(put-string port "hello")
(put-char port #\newline)
(force-output port)
(close-port port) ;;<-- this was not present in the previous version !!
)
So it seems that in order to write on the socket you need to call
""close.port"
But if the client closes the port, how can it receive a reply from the
server ?
- a network client,
Catonano <=