Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Creating timeouts for winsock connections

Posted on 2002-04-04
3
Medium Priority
?
278 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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 viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

609 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