?
Solved

Creating timeouts for winsock connections

Posted on 2002-04-04
3
Medium Priority
?
281 Views
Last Modified: 2013-11-13
I made a server application that accepts multiple connections and a client app for it.  I would like to add a timeout for when the client connects to the server.  If the client does not send the information in a certain amount of time, the server will close just that connection

Client connects to the server
Server requests a special code to authorize connection
Client responds with the code in the alloted amount of time and connection is authorized
If the client does not respond and it has been about 5 seconds, the server should close the connection immediately.

How would I do this?  Thanks
0
Comment
Question by:vpl4
  • 2
3 Comments
 
LVL 3

Accepted Solution

by:
y2kwacko earned 400 total points
ID: 6925577
I would assume you have a dynamic array of sockets although this will work if it was hard coded as well.  This is not code just the algorithm as such I do not expect anything for it.  If someone would like to code it, it should not take more then a few minutes.

Add timer control with index set to 0 interval set to 1000 (1 second) and enabled set to false

On connect request your code probably looks something like

socketcount = socketcount +1
load socket_control(socketcount)
socket_control(socketcount).tag = "0"
socket_control(socketcount).accept requestID

you should make it

load socket_control(socketcount)
load timer_control(socketcount)
socket_control(socketcount).accept requestID
timer_control.enabled = true


in the timer you should have something like the following the variable Index is from the control

socket_control(Index).tag = socket_control(Index).tag +1

rem every second socket_controls tag property gets incremented by 1

if socket_control(Index).tag = 30 then
    ....your code to send client error message...
    socket_control(Index).close
    ......code to unload control from memory.....
end if

-----------------------------------------------------------

you can of course change the line "if socket_control(Index).tag = 30 then" which is set to 30 seconds to any number you would like

20 second example:
  if socket_control(Index).tag = 20 then


Regards,
Kevin
0
 

Author Comment

by:vpl4
ID: 6929994
This sounds pretty good!  I'll try this and get back to you.
0
 

Author Comment

by:vpl4
ID: 6937860
I tried it and I got it to work!!!  Thanks a lot!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show, step by step, how to integrate R code into a R Sweave document
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses
Course of the Month14 days, 6 hours left to enroll

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question