PC Review


Reply
Thread Tools Rate Thread

How do I set read timeout value for a socket?

 
 
Peter Steele
Guest
Posts: n/a
 
      22nd Jul 2004
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?


 
Reply With Quote
 
 
 
 
Bill
Guest
Posts: n/a
 
      22nd Jul 2004
Use SetSocketOption

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

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


"Peter Steele" <(E-Mail Removed)> wrote in message
news:%23GRGiK$(E-Mail Removed)...
> 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?
>
>



 
Reply With Quote
 
Peter Steele
Guest
Posts: n/a
 
      22nd Jul 2004
That did the trick. Thanks very much!

Peter

"Bill" <(E-Mail Removed)> wrote in message
news:%23zypbk$(E-Mail Removed)...
> Use SetSocketOption
>
> s.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout,
> m_nMilliseconds);
>
> s.SetSocketOption(SocketOptionLevel.Socket,

SocketOptionName.ReceiveTimeout,
> m_nMilliseconds);
>
>
> "Peter Steele" <(E-Mail Removed)> wrote in message
> news:%23GRGiK$(E-Mail Removed)...
> > 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?
> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Socket timeout Hilton Microsoft Dot NET Compact Framework 4 18th Aug 2006 09:40 PM
Socket timeout =?Utf-8?B?TXVtbXk=?= Windows XP Networking 8 23rd Apr 2006 02:33 AM
Socket.Available != 0 but Socket.Read throws an exception Tomasz Naumowicz Microsoft C# .NET 0 24th Feb 2005 03:38 PM
Socket.Available != 0 but Socket.Read throws an exception Tomasz Naumowicz Microsoft C# .NET 0 24th Feb 2005 03:05 PM
Socket timeout =?Utf-8?B?UGFvbGE=?= Microsoft C# .NET 0 2nd Feb 2004 05:36 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:43 PM.