Professional Web Applications Themes

TCPserver client disconnect - Ruby

ruby newbie question... How can I detect when a client disconnects from a TCPserver? I'm streaming data to the client in a while loop (Shoutcast-style mp3 stream), but I'm not sure what condition to test to see if the client drops out. Thanks...

  1. #1

    Default TCPserver client disconnect

    ruby newbie question...

    How can I detect when a client disconnects from a TCPserver?
    I'm streaming data to the client in a while loop (Shoutcast-style mp3
    stream), but I'm not sure what condition to test to see if the client drops
    out.

    Thanks



    Noah Guest

  2. #2

    Default Re: TCPserver client disconnect

    Noah wrote: 

    Does sample/svr.rb (in the ruby distribution) help?


    Joel Guest

  3. #3

    Default Re: TCPserver client disconnect

    "Joel VanderWerf" <Berkeley.EDU> wrote in message
    news:berkeley.edu... [/ref]
    drops 
    >
    > Does sample/svr.rb (in the ruby distribution) help?
    >[/ref]
    Not really, because in that example, the server is checking for the client
    eof, right? (Correct me if I'm wrong. I just started with Ruby a few days
    ago.)

    In my application, the client makes one initial request, and then simply
    receives. The server is the only one sending data. It's like a HTTP
    request. Imagine a client does a GET on a very large file. The server
    begins to send the data, but the client drops out half-way through. How can
    the server detect this and cancel the transfer?



    Noah Guest

  4. #4

    Default Re: TCPserver client disconnect

    Noah wrote: [/ref]
    >
    > drops

    >>
    >>Does sample/svr.rb (in the ruby distribution) help?
    >>[/ref]
    >
    > Not really, because in that example, the server is checking for the client
    > eof, right? (Correct me if I'm wrong. I just started with Ruby a few days
    > ago.)
    >
    > In my application, the client makes one initial request, and then simply
    > receives. The server is the only one sending data. It's like a HTTP
    > request. Imagine a client does a GET on a very large file. The server
    > begins to send the data, but the client drops out half-way through. How can
    > the server detect this and cancel the transfer?[/ref]

    Errno::ECONNRESET seems to be the exception raised. At least on linux.

    In samples/svr.rb, I replaced

    s.write(str)

    with

    s.write(str*10_000)

    and ran samples/clnt.rb as usual. When the client is interrupted, the
    server receives:

    svr.rb:27:in `write': Connection reset by peer (Errno::ECONNRESET)
    from svr.rb:27
    from svr.rb:15:in `each'
    from svr.rb:15
    from svr.rb:12:in `loop'
    from svr.rb:12


    Joel Guest

  5. #5

    Default Re: TCPserver client disconnect


    "Joel VanderWerf" <Berkeley.EDU> wrote in message
    news:berkeley.edu... 
    > >
    > > drops
    > > 
    > >
    > > Not really, because in that example, the server is checking for the[/ref][/ref]
    client [/ref]
    days [/ref]
    can 
    >
    > Errno::ECONNRESET seems to be the exception raised. At least on linux.
    >
    > In samples/svr.rb, I replaced
    >
    > s.write(str)
    >
    > with
    >
    > s.write(str*10_000)
    >
    > and ran samples/clnt.rb as usual. When the client is interrupted, the
    > server receives:
    >
    > svr.rb:27:in `write': Connection reset by peer (Errno::ECONNRESET)
    > from svr.rb:27
    > from svr.rb:15:in `each'
    > from svr.rb:15
    > from svr.rb:12:in `loop'
    > from svr.rb:12
    >[/ref]
    Ah, it turns out I was generating that exception, but I couldn't see it
    because it was jumping to an 'ensure' block, and I guess the thread would
    just die. I moved the s.close into the ensure block and now it's working
    great.

    Thanks for the help.



    Noah Guest

  6. #6

    Default Re: TCPserver client disconnect

    Noah wrote: 

    In case you haven't come across it yet:

    Thread.abort_on_exception = true

    will abort the whole process, instead of just killing the thread
    quietly. Good for debugging...


    Joel Guest

Similar Threads

  1. application.disconnect( client )
    By dsdsdsdsd in forum Macromedia Flash Flashcom
    Replies: 0
    Last Post: August 23rd, 11:24 PM
  2. Flash Webcam client <-> client (not client <-> server<-> client)
    By bivald in forum Macromedia Flash Flashcom
    Replies: 0
    Last Post: April 24th, 10:33 PM
  3. How to disconnect a drb client?
    By Nathaniel in forum Ruby
    Replies: 3
    Last Post: January 8th, 01:48 PM
  4. TCPSocket subclass & TCPServer.accept
    By gabriele renzi in forum Ruby
    Replies: 1
    Last Post: September 9th, 10:35 PM
  5. I need to know how to disconnect ICS from client station
    By Dave Bailey in forum Windows Networking
    Replies: 1
    Last Post: July 10th, 06:52 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139