Networkstream Write problem

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

    #1

    Networkstream Write problem

    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 ?
    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

    Srinivas Loka


Working...