FAQ
I didn't find any clue in net package doc. So I post my question here.

I'm writing a simple tcp server with go. I wander how to know a connection
is broken in my read/write loop. I think the broken has 2 cases:
1. broken for local reason, such as closed at another function call or
network down, etc.
2. broken for remote reason, such as closed by remote conn.Close(), or
remote force close, etc.

How can I handle these cases? If some examples would be better.

thanks!

//br
aXe

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Dmitry Vyukov at Aug 17, 2013 at 2:14 pm
    If Read/Write give you non-nil error, there is something wrong with the
    connection.


    On Sat, Aug 17, 2013 at 6:12 PM, axe wrote:

    I didn't find any clue in net package doc. So I post my question here.

    I'm writing a simple tcp server with go. I wander how to know a connection
    is broken in my read/write loop. I think the broken has 2 cases:
    1. broken for local reason, such as closed at another function call or
    network down, etc.
    2. broken for remote reason, such as closed by remote conn.Close(), or
    remote force close, etc.

    How can I handle these cases? If some examples would be better.

    thanks!

    //br
    aXe

    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Axe at Aug 17, 2013 at 2:20 pm
    I don't think so. I tried read from connection when remote is down. I got
    the nil error but read length is zero.

    在 2013年8月17日星期六UTC+8下午10时13分55秒,Dmitry Vyukov写道:
    If Read/Write give you non-nil error, there is something wrong with the
    connection.



    On Sat, Aug 17, 2013 at 6:12 PM, axe <awu...@gmail.com <javascript:>>wrote:
    I didn't find any clue in net package doc. So I post my question here.

    I'm writing a simple tcp server with go. I wander how to know a
    connection is broken in my read/write loop. I think the broken has 2 cases:
    1. broken for local reason, such as closed at another function call or
    network down, etc.
    2. broken for remote reason, such as closed by remote conn.Close(), or
    remote force close, etc.

    How can I handle these cases? If some examples would be better.

    thanks!

    //br
    aXe

    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts...@googlegroups.com <javascript:>.
    For more options, visit https://groups.google.com/groups/opt_out.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Dmitry Vyukov at Aug 17, 2013 at 2:24 pm
    Are you using TCP conn? It must not return (0, nil), it must return (0,
    io.EOF).


    On Sat, Aug 17, 2013 at 6:20 PM, axe wrote:

    I don't think so. I tried read from connection when remote is down. I got
    the nil error but read length is zero.

    在 2013年8月17日星期六UTC+8下午10时13分55秒,Dmitry Vyukov写道:
    If Read/Write give you non-nil error, there is something wrong with the
    connection.


    On Sat, Aug 17, 2013 at 6:12 PM, axe wrote:

    I didn't find any clue in net package doc. So I post my question here.

    I'm writing a simple tcp server with go. I wander how to know a
    connection is broken in my read/write loop. I think the broken has 2 cases:
    1. broken for local reason, such as closed at another function call or
    network down, etc.
    2. broken for remote reason, such as closed by remote conn.Close(), or
    remote force close, etc.

    How can I handle these cases? If some examples would be better.

    thanks!

    //br
    aXe

    --
    You received this message because you are subscribed to the Google
    Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send
    an email to golang-nuts...@**googlegroups.com.

    For more options, visit https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out>
    .
    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Axe at Aug 17, 2013 at 2:35 pm
    opps! You are correct! I made a mistake when I read it. I used
    ioutil.ReadAll which has no EOF error report.
    Thanks!

    在 2013年8月17日星期六UTC+8下午10时24分16秒,Dmitry Vyukov写道:
    Are you using TCP conn? It must not return (0, nil), it must return (0,
    io.EOF).



    On Sat, Aug 17, 2013 at 6:20 PM, axe <awu...@gmail.com <javascript:>>wrote:
    I don't think so. I tried read from connection when remote is down. I got
    the nil error but read length is zero.

    在 2013年8月17日星期六UTC+8下午10时13分55秒,Dmitry Vyukov写道:
    If Read/Write give you non-nil error, there is something wrong with the
    connection.


    On Sat, Aug 17, 2013 at 6:12 PM, axe wrote:

    I didn't find any clue in net package doc. So I post my question here.

    I'm writing a simple tcp server with go. I wander how to know a
    connection is broken in my read/write loop. I think the broken has 2 cases:
    1. broken for local reason, such as closed at another function call or
    network down, etc.
    2. broken for remote reason, such as closed by remote conn.Close(), or
    remote force close, etc.

    How can I handle these cases? If some examples would be better.

    thanks!

    //br
    aXe

    --
    You received this message because you are subscribed to the Google
    Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send
    an email to golang-nuts...@**googlegroups.com.

    For more options, visit https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out>
    .
    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts...@googlegroups.com <javascript:>.
    For more options, visit https://groups.google.com/groups/opt_out.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Dmitry Vyukov at Aug 17, 2013 at 2:45 pm

    On Sat, Aug 17, 2013 at 6:35 PM, axe wrote:

    opps! You are correct! I made a mistake when I read it. I used
    ioutil.ReadAll which has no EOF error report.
    Thanks!
    If you io.Copy, then EOF is not an error. But you can determine that remote
    side properly closed the connection, if io.Copy returns.
    But you still need to check for other errors from io.Copy.




    在 2013年8月17日星期六UTC+8下午10时24分16秒,Dmitry Vyukov写道:
    Are you using TCP conn? It must not return (0, nil), it must return (0,
    io.EOF).


    On Sat, Aug 17, 2013 at 6:20 PM, axe wrote:

    I don't think so. I tried read from connection when remote is down. I
    got the nil error but read length is zero.

    在 2013年8月17日星期六UTC+8下午10时13分55秒,**Dmitry Vyukov写道:
    If Read/Write give you non-nil error, there is something wrong with the
    connection.


    On Sat, Aug 17, 2013 at 6:12 PM, axe wrote:

    I didn't find any clue in net package doc. So I post my question here.

    I'm writing a simple tcp server with go. I wander how to know a
    connection is broken in my read/write loop. I think the broken has 2 cases:
    1. broken for local reason, such as closed at another function call or
    network down, etc.
    2. broken for remote reason, such as closed by remote conn.Close(), or
    remote force close, etc.

    How can I handle these cases? If some examples would be better.

    thanks!

    //br
    aXe

    --
    You received this message because you are subscribed to the Google
    Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send
    an email to golang-nuts...@**googlegroups.**com.

    For more options, visit https://groups.google.com/**grou**ps/opt_out<https://groups.google.com/groups/opt_out>
    .
    --
    You received this message because you are subscribed to the Google
    Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send
    an email to golang-nuts...@**googlegroups.com.
    For more options, visit https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out>
    .
    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Ives van der Flaas at Aug 17, 2013 at 2:46 pm
    Although the absence of an error does not mean everything is okay. The
    connection could be dead for a very long time without any way of noticing.

    On Sat, Aug 17, 2013 at 4:13 PM, Dmitry Vyukov wrote:

    If Read/Write give you non-nil error, there is something wrong with the
    connection.


    On Sat, Aug 17, 2013 at 6:12 PM, axe wrote:

    I didn't find any clue in net package doc. So I post my question here.

    I'm writing a simple tcp server with go. I wander how to know a
    connection is broken in my read/write loop. I think the broken has 2 cases:
    1. broken for local reason, such as closed at another function call or
    network down, etc.
    2. broken for remote reason, such as closed by remote conn.Close(), or
    remote force close, etc.

    How can I handle these cases? If some examples would be better.

    thanks!

    //br
    aXe

    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.


    --
    Ives van der Flaas
    ☎ 0499/31.54.37

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Lubos Pintes at Aug 17, 2013 at 3:27 pm
    So this means that there is no "connection closed event", or another
    indication?

    Dňa 17. 8. 2013 16:46 Ives van der Flaas wrote / napísal(a):
    Although the absence of an error does not mean everything is okay. The
    connection could be dead for a very long time without any way of noticing.


    On Sat, Aug 17, 2013 at 4:13 PM, Dmitry Vyukov
    wrote:

    If Read/Write give you non-nil error, there is something wrong with
    the connection.



    On Sat, Aug 17, 2013 at 6:12 PM, axe
    wrote:

    I didn't find any clue in net package doc. So I post my question
    here.

    I'm writing a simple tcp server with go. I wander how to know a
    connection is broken in my read/write loop. I think the broken
    has 2 cases:
    1. broken for local reason, such as closed at another function
    call or network down, etc.
    2. broken for remote reason, such as closed by remote
    conn.Close(), or remote force close, etc.

    How can I handle these cases? If some examples would be better.

    thanks!

    //br
    aXe

    --
    You received this message because you are subscribed to the
    Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from
    it, send an email to
    golang-nuts+unsubscribe@googlegroups.com
    For more options, visit https://groups.google.com/groups/opt_out.


    --
    You received this message because you are subscribed to the Google
    Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it,
    send an email to
    golang-nuts+unsubscribe@googlegroups.com
    For more options, visit https://groups.google.com/groups/opt_out.




    --
    Ives van der Flaas
    ☎ 0499/31.54.37

    --
    You received this message because you are subscribed to the Google
    Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send
    an email to
    golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Christoph Hack at Aug 17, 2013 at 5:17 pm

    On Saturday, August 17, 2013 5:27:39 PM UTC+2, Lubos Pintes wrote:

    So this means that there is no "connection closed event", or another
    indication?
    There is a closed event in TCP that is sent when the remote host closes the
    socket. But if the remote just disappears, you
    will not get the event. You can still write to the Conn without getting any
    error and your OS will still send the packages, but
    they might never reach their location.

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Axe at Aug 17, 2013 at 5:12 pm
    Does the alive connection lead an EOF when io.Copy used upon it under
    certain case? Then wha'ts the case?

    在 2013年8月17日星期六UTC+8下午10时46分02秒,Ives van der Flaas写道:
    Although the absence of an error does not mean everything is okay. The
    connection could be dead for a very long time without any way of noticing.


    On Sat, Aug 17, 2013 at 4:13 PM, Dmitry Vyukov <dvy...@google.com<javascript:>
    wrote:
    If Read/Write give you non-nil error, there is something wrong with the
    connection.



    On Sat, Aug 17, 2013 at 6:12 PM, axe <awu...@gmail.com <javascript:>>wrote:
    I didn't find any clue in net package doc. So I post my question here.

    I'm writing a simple tcp server with go. I wander how to know a
    connection is broken in my read/write loop. I think the broken has 2 cases:
    1. broken for local reason, such as closed at another function call or
    network down, etc.
    2. broken for remote reason, such as closed by remote conn.Close(), or
    remote force close, etc.

    How can I handle these cases? If some examples would be better.

    thanks!

    //br
    aXe

    --
    You received this message because you are subscribed to the Google
    Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send
    an email to golang-nuts...@googlegroups.com <javascript:>.
    For more options, visit https://groups.google.com/groups/opt_out.
    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts...@googlegroups.com <javascript:>.
    For more options, visit https://groups.google.com/groups/opt_out.


    --
    Ives van der Flaas
    ☎ 0499/31.54.37
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Dmitry Vyukov at Aug 17, 2013 at 5:14 pm
    io.Copy on alive connection will not return at all.


    On Sat, Aug 17, 2013 at 9:11 PM, axe wrote:

    Does the alive connection lead an EOF when io.Copy used upon it under
    certain case? Then wha'ts the case?

    在 2013年8月17日星期六UTC+8下午10时46分02秒,Ives van der Flaas写道:
    Although the absence of an error does not mean everything is okay. The
    connection could be dead for a very long time without any way of noticing.

    On Sat, Aug 17, 2013 at 4:13 PM, Dmitry Vyukov wrote:

    If Read/Write give you non-nil error, there is something wrong with
    the connection.


    On Sat, Aug 17, 2013 at 6:12 PM, axe wrote:

    I didn't find any clue in net package doc. So I post my question here.

    I'm writing a simple tcp server with go. I wander how to know a
    connection is broken in my read/write loop. I think the broken has 2 cases:
    1. broken for local reason, such as closed at another function call or
    network down, etc.
    2. broken for remote reason, such as closed by remote conn.Close(), or
    remote force close, etc.

    How can I handle these cases? If some examples would be better.

    thanks!

    //br
    aXe

    --
    You received this message because you are subscribed to the Google
    Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send
    an email to golang-nuts...@**googlegroups.com.

    For more options, visit https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out>
    .
    --
    You received this message because you are subscribed to the Google
    Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send
    an email to golang-nuts...@**googlegroups.com.

    For more options, visit https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out>
    .


    --
    Ives van der Flaas
    ☎ 0499/31.54.37
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedAug 17, '13 at 2:12p
activeAug 17, '13 at 5:17p
posts11
users5
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase