guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to notice abrupt tcp connection losses in server/client?


From: Zelphir Kaltstahl
Subject: How to notice abrupt tcp connection losses in server/client?
Date: Thu, 21 Jun 2018 08:22:36 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0

Hello Guile users,

I wrote some TCP server and client in Guile which I have uploaded here:

https://gitlab.com/zelphir-kaltstahl-projects/guile-scheme-tutorials-and-examples/raw/dev/network-programming/tcp-client.scm

and here:

https://gitlab.com/zelphir-kaltstahl-projects/guile-scheme-tutorials-and-examples/raw/dev/network-programming/tcp-server.scm

or normal GitLab view:

https://gitlab.com/zelphir-kaltstahl-projects/guile-scheme-tutorials-and-examples/tree/dev/network-programming

(Is it OK to post these as links, or always better to include all
relevant source code on the mailing list? On other e-mail lists I have
experienced that my message was too long and got truncated, so I posted
the code as links to the raw file on GitLab.)

The loop for reacting on messages from a client on the server looks like
this:

(while #t
  (let* ([bytes-count (recv! in-out-sock receive-buffer)]
         [message-received (byte-vector->utf8-message receive-buffer 
bytes-count)])
    (message-handler client-connection message-received))))))

But this has a problem: When I run both client and server in two
terminals and then exit the client using Ctrl-D, the server somehow gets
stuck in the loop always receiving the empty string. Since that is 0
Bytes long, it does not really take anything from the socket (if I
understand correctly), but instead can recv! in the next iteration again
immediately. The only thing that works then for stopping this loop is to
hold down Ctrl-C on the server for a second or so.
The same happens for the client receiving message loop, because that one
also does not detect me suddenly interrupting or killing the server and
then loops on the empty string.
At first I thought if I caught eof-object? and then (break) the loop it
would solve the problem, but apparently it does not.
Basically I would like the server and client to be prepared for non
proper shutdown of either.

How can I handle / detect abrupt connection losses, so that I can break
the message handling loop?

On 20.06.2018 18:00, address@hidden wrote:
> Send guile-user mailing list submissions to
>       address@hidden
>
> To subscribe or unsubscribe via the World Wide Web, visit
>       https://lists.gnu.org/mailman/listinfo/guile-user
> or, via email, send a message with subject or body 'help' to
>       address@hidden
>
> You can reach the person managing the list at
>       address@hidden
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of guile-user digest..."
>
>
> Today's Topics:
>
>    1. Re: lat? and atom? not in guile? (Thompson, David)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Wed, 20 Jun 2018 10:55:43 -0400
> From: "Thompson, David" <address@hidden>
> To: John Cowan <address@hidden>
> Cc: Joshua Branson <address@hidden>, Guile User
>       <address@hidden>
> Subject: Re: lat? and atom? not in guile?
> Message-ID:
>       <address@hidden>
> Content-Type: text/plain; charset="UTF-8"
>
> On Wed, Jun 20, 2018 at 10:40 AM, John Cowan <address@hidden> wrote:
>> On Wed, Jun 20, 2018 at 10:37 AM, Joshua Branson <address@hidden>
>> wrote:
>>
>>
>>> Oh hey David!  Thanks for the explanation!  Maybe I need to take another
>>> look at that book then.  I found it a little repetitive, but I am
>>> probably not quite grasping some of the fundamentals.
>>>
>> It's meant to be repetitive.  It's explicitly compared in the introduction
>> to Hanon's finger exercises for the piano:  C-E-F-G-A-G-F-E,
>> D-F-G-A-B-A-G-F, E-G-A-B-C-B-A-D and so on forever, up the scale and down
>> in every key.  Boring as hell, but just the thing to get fluency into your
>> fingers.
> It's repetitive but honestly I found that the comedic writing made the
> exercises very entertaining. I was rarely bored.  I don't play the
> piano, but I do play drums, and the equivalent to Hanon's finger
> exercises is an old book called Stick Control, which is definitely in
> the boring as hell category! I'm glad that Lisp beginners have
> something more fun available. :)
>
> - Dave
>
>
>
> ------------------------------
>
> Subject: Digest Footer
>
> _______________________________________________
> guile-user mailing list
> address@hidden
> https://lists.gnu.org/mailman/listinfo/guile-user
>
>
> ------------------------------
>
> End of guile-user Digest, Vol 187, Issue 14
> *******************************************




reply via email to

[Prev in Thread] Current Thread [Next in Thread]