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
Solved

Creating timeouts for winsock connections

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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.
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.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

828 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