Socket TCP questiuon.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Anders Both

    #1

    Socket TCP questiuon.

    If you send data using TCP and Socket, can the client then be 100% sure that
    if it send´s data and no exception uccur, then the data will also arrived in
    a a correct way on the server.

    What if e.g. some router on the way has restarted or if it restarts just in
    the same time as the data is beeing send.

    ?


  • Konrad Neitzel

    #2
    Re: Socket TCP questiuon.

    Hi Anders!

    "Anders Both" <andersboth@hot mail.com> schrieb im Newsbeitrag
    news:O5o0hvPrDH A.2692@TK2MSFTN GP09.phx.gbl...
    [color=blue]
    > If you send data using TCP and Socket, can the client then be 100%[/color]
    sure that[color=blue]
    > if it send´s data and no exception uccur, then the data will also[/color]
    arrived in[color=blue]
    > a a correct way on the server.[/color]
    [color=blue]
    > What if e.g. some router on the way has restarted or if it restarts[/color]
    just in[color=blue]
    > the same time as the data is beeing send.[/color]

    If you use UDP, then your application must handle these things.
    If you use TCP, then the System itself is doing the whole work for you.
    (e.g. sending parts of your data in packages, waiting for an
    acknowkledge-message, resending data if a packet is lost ...

    If everything clear now, or do you need more details? Or do you have a
    concrete problem that should be solved?

    With kind regards,

    Konrad


    Comment

    • Anders Both

      #3
      Re: Socket TCP questiuon.

      OK, Thx. I will look deper in to it.

      Best Regards

      Anders Both

      "Konrad Neitzel" <neitzel@neitze l.de> wrote in message
      news:OI4Dz2PrDH A.2000@TK2MSFTN GP12.phx.gbl...[color=blue]
      > Hi Anders!
      >
      > "Anders Both" <andersboth@hot mail.com> schrieb im Newsbeitrag
      > news:O5o0hvPrDH A.2692@TK2MSFTN GP09.phx.gbl...
      >[color=green]
      > > If you send data using TCP and Socket, can the client then be 100%[/color]
      > sure that[color=green]
      > > if it send´s data and no exception uccur, then the data will also[/color]
      > arrived in[color=green]
      > > a a correct way on the server.[/color]
      >[color=green]
      > > What if e.g. some router on the way has restarted or if it restarts[/color]
      > just in[color=green]
      > > the same time as the data is beeing send.[/color]
      >
      > If you use UDP, then your application must handle these things.
      > If you use TCP, then the System itself is doing the whole work for you.
      > (e.g. sending parts of your data in packages, waiting for an
      > acknowkledge-message, resending data if a packet is lost ...
      >
      > If everything clear now, or do you need more details? Or do you have a
      > concrete problem that should be solved?
      >
      > With kind regards,
      >
      > Konrad
      >
      >[/color]


      Comment

      • Anders Both

        #4
        Re: Socket TCP questiuon.

        I am back already.

        But what if you have a socket connection between a client and a server. And
        the server sometimes send´s some data to the client, like lets say every 5
        minute, and the client is just waiting to reseive this data. What if the
        server frezzes or if the connection is lost in some way, how (if it is
        alerted) will the client then be allerted when using asynchronous Sockets
        (TCP).

        Best Regards Anders Both

        "Konrad Neitzel" <neitzel@neitze l.de> wrote in message
        news:OI4Dz2PrDH A.2000@TK2MSFTN GP12.phx.gbl...[color=blue]
        > Hi Anders!
        >
        > "Anders Both" <andersboth@hot mail.com> schrieb im Newsbeitrag
        > news:O5o0hvPrDH A.2692@TK2MSFTN GP09.phx.gbl...
        >[color=green]
        > > If you send data using TCP and Socket, can the client then be 100%[/color]
        > sure that[color=green]
        > > if it send´s data and no exception uccur, then the data will also[/color]
        > arrived in[color=green]
        > > a a correct way on the server.[/color]
        >[color=green]
        > > What if e.g. some router on the way has restarted or if it restarts[/color]
        > just in[color=green]
        > > the same time as the data is beeing send.[/color]
        >
        > If you use UDP, then your application must handle these things.
        > If you use TCP, then the System itself is doing the whole work for you.
        > (e.g. sending parts of your data in packages, waiting for an
        > acknowkledge-message, resending data if a packet is lost ...
        >
        > If everything clear now, or do you need more details? Or do you have a
        > concrete problem that should be solved?
        >
        > With kind regards,
        >
        > Konrad
        >
        >[/color]


        Comment

        • Konrad Neitzel

          #5
          Re: Socket TCP questiuon.

          Hi Anders!

          "Anders Both" <andersboth@hot mail.com> schrieb im Newsbeitrag
          news:uaY%23MOfr DHA.1872@TK2MSF TNGP09.phx.gbl. ..
          [color=blue]
          > But what if you have a socket connection between a client and a[/color]
          server. And[color=blue]
          > the server sometimes send´s some data to the client, like lets say[/color]
          every 5[color=blue]
          > minute, and the client is just waiting to reseive this data.[/color]
          I think, that it is recommend to send some dummy stuff like "pings"
          through this connection. (Or this is the way, I am going on -> server
          side <- to be sure, that all clients are still alive ...
          [color=blue]
          > What if the
          > server frezzes or if the connection is lost in some way, how (if it is
          > alerted) will the client then be allerted when using asynchronous[/color]
          Sockets[color=blue]
          > (TCP).[/color]

          I haven't tested this stuff until now. If the server didn't respond,
          because simply a thread is locked, then you will not recognize it. But
          the connection should be closed, if the server crashes or there will be
          a network problem for some time ... But as I told you: I am not that
          sure - You had to test that a little first!

          If you need multiple clients to connect to a server and simply get some
          information every 5 mins: Ever thought about remoting? Then all you have
          to do is calling a function in an Remote Object .... That could be much
          better and much easier than building a tcp/ip solution on your own.

          With kind regards,

          Konrad


          Comment

          • Anders Both

            #6
            Re: Socket TCP questiuon.

            Thx,

            I can not use remoting, because the connection has to be from a java client
            on a web-page to a c# service.

            But I will find out everything.

            Thx alot.

            "Konrad Neitzel" <neitzel@neitze l.de> wrote in message
            news:erTfR$lrDH A.684@TK2MSFTNG P09.phx.gbl...[color=blue]
            > Hi Anders!
            >
            > "Anders Both" <andersboth@hot mail.com> schrieb im Newsbeitrag
            > news:uaY%23MOfr DHA.1872@TK2MSF TNGP09.phx.gbl. ..
            >[color=green]
            > > But what if you have a socket connection between a client and a[/color]
            > server. And[color=green]
            > > the server sometimes send´s some data to the client, like lets say[/color]
            > every 5[color=green]
            > > minute, and the client is just waiting to reseive this data.[/color]
            > I think, that it is recommend to send some dummy stuff like "pings"
            > through this connection. (Or this is the way, I am going on -> server
            > side <- to be sure, that all clients are still alive ...
            >[color=green]
            > > What if the
            > > server frezzes or if the connection is lost in some way, how (if it is
            > > alerted) will the client then be allerted when using asynchronous[/color]
            > Sockets[color=green]
            > > (TCP).[/color]
            >
            > I haven't tested this stuff until now. If the server didn't respond,
            > because simply a thread is locked, then you will not recognize it. But
            > the connection should be closed, if the server crashes or there will be
            > a network problem for some time ... But as I told you: I am not that
            > sure - You had to test that a little first!
            >
            > If you need multiple clients to connect to a server and simply get some
            > information every 5 mins: Ever thought about remoting? Then all you have
            > to do is calling a function in an Remote Object .... That could be much
            > better and much easier than building a tcp/ip solution on your own.
            >
            > With kind regards,
            >
            > Konrad
            >
            >[/color]


            Comment

            • Scott Gaitskell

              #7
              Re: Socket TCP question

              "Anders Both" <andersboth@hot mail.com> wrote in
              news:#4fZr1nrDH A.2304@tk2msftn gp13.phx.gbl:
              [color=blue]
              > Thx,
              >
              > I can not use remoting, because the connection has to be from a java
              > client on a web-page to a c# service.
              >
              > But I will find out everything.
              >
              > Thx alot.
              >
              > "Konrad Neitzel" <neitzel@neitze l.de> wrote in message
              > news:erTfR$lrDH A.684@TK2MSFTNG P09.phx.gbl...[color=green]
              >> Hi Anders!
              >>
              >> "Anders Both" <andersboth@hot mail.com> schrieb im Newsbeitrag
              >> news:uaY%23MOfr DHA.1872@TK2MSF TNGP09.phx.gbl. ..
              >>[color=darkred]
              >> > But what if you have a socket connection between a client and a[/color]
              >> server. And[color=darkred]
              >> > the server sometimes send´s some data to the client, like lets say[/color]
              >> every 5[color=darkred]
              >> > minute, and the client is just waiting to reseive this data.[/color]
              >> I think, that it is recommend to send some dummy stuff like "pings"
              >> through this connection. (Or this is the way, I am going on -> server
              >> side <- to be sure, that all clients are still alive ...
              >>[color=darkred]
              >> > What if the
              >> > server frezzes or if the connection is lost in some way, how (if it
              >> > is alerted) will the client then be allerted when using
              >> > asynchronous[/color]
              >> Sockets[color=darkred]
              >> > (TCP).[/color]
              >>
              >> I haven't tested this stuff until now. If the server didn't respond,
              >> because simply a thread is locked, then you will not recognize it.
              >> But the connection should be closed, if the server crashes or there
              >> will be a network problem for some time ... But as I told you: I am
              >> not that sure - You had to test that a little first!
              >>
              >> If you need multiple clients to connect to a server and simply get
              >> some information every 5 mins: Ever thought about remoting? Then all
              >> you have to do is calling a function in an Remote Object .... That
              >> could be much better and much easier than building a tcp/ip solution
              >> on your own.
              >>
              >> With kind regards,
              >>
              >> Konrad
              >>
              >>[/color]
              >
              >
              >[/color]

              Anders,

              You may have already found an answer for this, if not, hopefully this
              helps.


              The only way the client can know that the connection is gone, is if the
              connection is closed by the server, or the client tries to send a data
              packet, but hits its timeout period on the send method.

              If the connection is lost, for example a router dies, then the only way to
              know the connection is gone, is from a timeout, as you will never get the
              shutdown (fin) message from the socket that initiated the shutdown/close.

              You have two simple options that I can think of off the top of my head.

              You can make the clients repond to the servers data, and have the
              SendTimeout option set on the client sockets.
              Below is from the MSDN help.

              // Send operations will time-out if confirmation
              // is not received within 1000 milliseconds.
              s.SetSocketOpti on (SocketOptionLe vel.Socket, SocketOptionNam e.SendTimeout,
              1000);


              Your other options is if the server is known to always send data at a
              specific interval, then you can use a timer to watch for a missed packet.
              Or you can send Keep-Alive messages every 10 seconds, if the data is not
              regular enough, or you don't want the sockets locked for longer than
              necessary with a lost connection.

              So if the server sends "Alive" every 5 seconds, then set a timer's timeout
              period to 10 seconds. Whenever any data arrives on the socket, reset the
              timer. If the timers Elapsed event is raised, then you know the server is
              possibly not responding.

              For more detail on Socket programming for C#, you can not go past Richard
              Blum's book "C# Network Programming" - published by Sybex.


              Scott Gaitskell

              Comment

              Working...