Solved

Creating timeouts for winsock connections

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

Technology Partners: 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

Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

717 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