NetworkStream Write Not Failing

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Srinivas R. Loka

    NetworkStream Write Not Failing

    I have a TCP server to which a number of mobile devices connect. If a device
    disconnects(mos tly no clean close as they usually lose cell coverage or
    shutdown), and the server then tries to send data using the
    Networkstream.W rite method, its NOT throwing an exception. I am using the
    TCPClient class.
    I am able to reproduce this by shutting down my test device(turning off
    power) and then sending some data. The Write just finishes as if the data
    was sent.
    Is there some timeout that has to occur before the Write fails ?

    Thanks

    Srinivas


  • AstroDrabb

    #2
    Re: NetworkStream Write Not Failing

    Are you using a NetworkStream to write? If so, just check the CanWrite property

    TcpClient tcp = new TcpClient("www. google.com", 80)
    NetworkStream ns = new NetworkStream(t cp, true)
    if (ns.CanWrite

    ns.Write(myByte s, 0, 256)



    ---
    Posted using Wimdows.net Newsgroups - http://www.wimdows.net/newsgroups/

    Comment

    • SRLoka

      #3
      Re: NetworkStream Write Not Failing

      Thanks for the reply.
      Yes I am using the NetworkStream. Even the CanWrite returns true. Here is
      part of the code that writes

      if (Cmd != "")
      {
      try
      {
      byte[] OTA = Encoding.ASCII. GetBytes(Cmd);
      try
      {
      if(_NetworkStre am.DataAvailabl e)
      {
      //JUst to check for connection
      }
      }
      catch (SocketExceptio n) //remote closed
      {
      this.CloseSocke t();
      return;
      }
      if(_NetworkStre am.CanWrite)
      {
      _NetworkStream. Write(OTA,0,(in t)OTA.Length);
      }
      }
      catch(Exception eOTA)
      {
      Controller.EMai lErr("OTA Send Error",eOTA.Mes sage.ToString() );
      }
      }


      The mobile unit is a third party device and I just power it down to simulate
      a lost TCP connection.
      I even used DataAvailable as it is supposed to throw an exception if remote
      disconnects. Even after I shutdown the remote device, the CanWrite returns
      true and the Write does not thrown an exception.
      The mobile unit connects using a wireless cellular network(ATT/cingular) -
      would that have something to do with it ?

      Thanks again


      "AstroDrabb " <AstroDrabb@-NOSPAM-yahoo.com> wrote in message
      news:uyI6GIcVFH A.3532@TK2MSFTN GP09.phx.gbl...[color=blue]
      > Are you using a NetworkStream to write? If so, just check the CanWrite
      > property.
      >
      > TcpClient tcp = new TcpClient("www. google.com", 80);
      > NetworkStream ns = new NetworkStream(t cp, true);
      > if (ns.CanWrite)
      > {
      > ns.Write(myByte s, 0, 256);
      > }
      >
      >
      > ---
      > Posted using Wimdows.net Newsgroups - http://www.wimdows.net/newsgroups/[/color]


      Comment

      Working...