.NET Components for Mobility

Stream.ReadTimeout and alternative solutions

Last post 09-10-2008 8:49 AM by alanjmcf. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 09-04-2008 10:52 AM

    Stream.ReadTimeout and alternative solutions

    Hi there,

     

    I'm trying to use the ReadTimeout property to prevent a block when I call stream.read. I have my read running on a seperate thread, but I believe when it blocks, even if on another thread I cannot send on that same stream. Is that a correct assumption?  When I try and set the ReadTimeout of the I get a NullReferenceException. Thissomewhat makes sense since my ReadTimeout property is a member of NetworkStream. NetworkStream requires an instance which takes a socket as a parameter upon class instantiation. This is where I am confused. I didn't think I'd need to use an independent socket when using getStream(). 

     So in a nutshell what is happening is on the main thread I have a checkconnection timer that fires and send a ping to a remote device. When that remote device receives the ping, it sends back a response and the sender is then supposed to receive that response. The problem is that my receiver thread is blocking in the Read(param1, param2, param3) call which in turn prevents anymore pings being sent out. At that point I lose all comms.

     

    Thanks,

    Mike

     

    Edit: And yes I am only setting ReadTimout after I call GetStream()

  • 09-10-2008 8:49 AM In reply to

    Re: Stream.ReadTimeout and alternative solutions

    So are you doing something like?

        NetworkStream peer = cli.GetStream();
        peer.ReadTimeout = ......;
        int readLen = peer.Read(...)

    ReadTimeout sets the timeout on one stream/one socket/one RFCOMM connection not globally.

    If you've got connections to various devices then to keep things responsive you'd likely need one thread per device, or use asynchronous sockets/stream (e.g. BeginRead)

    Alan J. McFarlane
    http://www.alanjmcf.me.uk/
    Please follow-up in the newsgroup for the benefit of all.
    Have I helped? Consider visiting my Amazon wishlist, see my homepage.
Page 1 of 1 (2 items)
Copyright © 2001-2008 In The Hand Ltd. All rights reserved. Terms of Use and Privacy Policy.