Hi there,
I need to do some simple network communication. My program can act as both a server and client. When it's a server I create a TcpListener, start it, check whether listener.Pending() is true, and then create a TcpClient from which I create a NetworkStream which I write my data too. So that works just fine. Now on the client side, I create a TcpClient and grab a NetworkStream from it. Here's my problem, so when I now call NetworkStream.Read it'll connect just fine if I have my server is running. But, if I don't have my server running then it'll sit there for a little while trying to connect and then come back and throw an exception, not the behaviour I want. I tried using NetworkSteam.DataAvailable to check whether the server was there, but that's not really what I want because it assumes there's a server and just checks on the data, which of course throws an exception when the servers not running. What I want my client program to do is basically poll to see whether the servers there in a while loop until it finds it. So far I've just had to deal with the TcpListener and TcpClient classes which are nice and easy to use, am I going to have to go down to the Socket level to do this Or is there some object that I can easily grab to check whether a server is up and running before I try and read
Thanks for any help,
Chris

Checking whether a server using TcpListener is broadcasting.
AronR
This is a general issue. There is no connection timeout now so you
have to wait for the connection to time out when the server is not listening.
If it is really important for you to do you can do the following..
1. If the server and client are on the same machine, then the server, after starting to listen, can create a mutex with a unique name.
2. The client can try to create a mutex with the same name. if the client is able to
create it then the server is not there. If the client fails to create then the server is there and so the client can connect to it.
You can do some variation of the same with a registry or a file.
in this case the server can create a registry key or a file on the disk and the
client can test for the existense to know that the server is there.
When the server is done, it should delete the reg key or file.
If the client and server or on a different machine, then you can use UDP for synchronization. The client listens for a UDP packet from the server. The server periodically sends a UDP packet to annouce its presence.
In any case there is no easy to detect that the server is up and listening
In Windows Vista this is resolved with a connection timeout
Scott_Piegdon