If I use TCPClient, it's straightforward to set the read timeout value for
reading the associated stream:

TcpClient myClient = new TcpClient(myaddr, myport);
myClient.ReceiveTimeout = 5000;
NetworkStream myClientStream = myClient.GetStream();
myClientReader = new StreamReader(myClientStream );

However, if I've just accepted a socket connection via a listener, the
situation is a bit different. I

clientSocket = server.AcceptSocket();
NetworkStream myClientStream = new NetworkStream(clientSocket );
myClientReader = new StreamReader(myClientStream);

I'd like to do something like this:

clientSocket.ReceiveTimeout = 5000;

but there is not such method on sockets. So how can I do the equivalent
operation of setting the timeout for a socket like I can do with a TcpClient
object?

Re: How do I set read timeout value for a socket? by Bill

Bill
Thu Jul 22 09:35:06 CDT 2004

Use SetSocketOption

s.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout,
m_nMilliseconds);

s.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout,
m_nMilliseconds);


"Peter Steele" <psteele@z-force.com> wrote in message
news:%23GRGiK$bEHA.3944@tk2msftngp13.phx.gbl...
> If I use TCPClient, it's straightforward to set the read timeout value for
> reading the associated stream:
>
> TcpClient myClient = new TcpClient(myaddr, myport);
> myClient.ReceiveTimeout = 5000;
> NetworkStream myClientStream = myClient.GetStream();
> myClientReader = new StreamReader(myClientStream );
>
> However, if I've just accepted a socket connection via a listener, the
> situation is a bit different. I
>
> clientSocket = server.AcceptSocket();
> NetworkStream myClientStream = new NetworkStream(clientSocket );
> myClientReader = new StreamReader(myClientStream);
>
> I'd like to do something like this:
>
> clientSocket.ReceiveTimeout = 5000;
>
> but there is not such method on sockets. So how can I do the equivalent
> operation of setting the timeout for a socket like I can do with a
TcpClient
> object?
>
>



Re: How do I set read timeout value for a socket? by Peter

Peter
Thu Jul 22 16:40:20 CDT 2004

That did the trick. Thanks very much!

Peter

"Bill" <msgdev@hotmail.com> wrote in message
news:%23zypbk$bEHA.1652@TK2MSFTNGP09.phx.gbl...
> Use SetSocketOption
>
> s.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout,
> m_nMilliseconds);
>
> s.SetSocketOption(SocketOptionLevel.Socket,
SocketOptionName.ReceiveTimeout,
> m_nMilliseconds);
>
>
> "Peter Steele" <psteele@z-force.com> wrote in message
> news:%23GRGiK$bEHA.3944@tk2msftngp13.phx.gbl...
> > If I use TCPClient, it's straightforward to set the read timeout value
for
> > reading the associated stream:
> >
> > TcpClient myClient = new TcpClient(myaddr, myport);
> > myClient.ReceiveTimeout = 5000;
> > NetworkStream myClientStream = myClient.GetStream();
> > myClientReader = new StreamReader(myClientStream );
> >
> > However, if I've just accepted a socket connection via a listener, the
> > situation is a bit different. I
> >
> > clientSocket = server.AcceptSocket();
> > NetworkStream myClientStream = new NetworkStream(clientSocket );
> > myClientReader = new StreamReader(myClientStream);
> >
> > I'd like to do something like this:
> >
> > clientSocket.ReceiveTimeout = 5000;
> >
> > but there is not such method on sockets. So how can I do the equivalent
> > operation of setting the timeout for a socket like I can do with a
> TcpClient
> > object?
> >
> >
>
>