Solved

Creating timeouts for winsock connections

Posted on 2002-04-04
3
202 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 100 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now