How to listen server for 10 Minutes and then terminate

I want my server socket to listen for 10 minutes or for specific time and then terminate the connection. Please guide me how to do this?How can i set the time for this?

LVL 5
muhammadyasirAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
omraviprakashConnect With a Mentor Commented:
Approach can be taken to start a timer as soon as you have your server listening for the connections. You can set the timer to a value of 10 min. As soon as you have a connection from client coming, you can stop the timer. Else, if the timer timesout in 10min, you can close the server listening port or exist gracefully.
0
 
CSecurityConnect With a Mentor Commented:
Create a timer, look:
http://www.c-sharpcorner.com/UploadFile/mahesh/WorkingwithTimerControlinCSharp11302005054911AM/WorkingwithTimerControlinCSharp.aspx

Then on the time you defined, close the connection: Socket.Close()

That's all
0
 
CSecurityConnect With a Mentor Commented:
Create a timer object in your form, then set it's interval to 600000 (it's in millisecond, means 10 min)

Then

private void timer1_Tick(object sender, System.EventArgs e)
{
Socket.Close();
}
0
 
muhammadyasirAuthor Commented:
Sorry to say I did write my question properly, i am rephrasing it.

I want my server to listen for 10 minutes if no connection is being received with in these 10 minutes then i have to terminate the server.

Thanks
0
 
CSecurityConnect With a Mentor Commented:
Do this:

If (checkSocket.Connected == false) then checkSocket.close()
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.