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?

Who is Participating?

Improve company productivity with a Business Account.Sign Up

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.
CSecurityConnect With a Mentor Commented:
Create a timer, look:

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

That's all
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)


private void timer1_Tick(object sender, System.EventArgs e)
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.

CSecurityConnect With a Mentor Commented:
Do this:

If (checkSocket.Connected == false) then checkSocket.close()
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.