Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 471
  • Last Modified:

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?

0
muhammadyasir
Asked:
muhammadyasir
  • 3
4 Solutions
 
CSecurityCommented:
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
 
CSecurityCommented:
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
 
CSecurityCommented:
Do this:

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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now