Hi everybody,
I have a problem that I havent figured out the reason behind it yet. When a client connects to my server, and lets say stays connected for an hour or so, the server doesnt realize if the client exits.
But it works when they are connected for respectively small amount of time.
I do not have a ping system to check whether a client is idle or not. Does anybody have any ideas?
How comes a winsock control cant realize that the client is not connected anymore?
EpcH
Squidge
03-30-2003, 11:59 PM
here is a little idea......
if the client exits send the command "///E" to the server then
all data comming into the server cheacks to see if it begins with"///E
if so disconnect from the client :)
hope that gives you some idea :-D
Uplink2069
03-31-2003, 12:33 AM
i had this prob when i first started working with winsock. in the close event (im assuming your using an array of winsocks for manage connections) you need to close the connection on server-side then reset it to accept new connections:
Private Sub Winsock1_Close(Index as Integer)
Winsock1(index).Close
Winsock1(Index).Listern
End sub
rust710
03-31-2003, 05:43 AM
I think that you should proably have the client send a disconnection signal to the server when it disconnects. You shouldn't have a problem with disconnection, regardless of how long you have been connected. This problem is strange but not unheard of.
Private Sub sckConnection_Close(index As Integer)
Dim sockmatck As Integer
Dim temp As Integer
'----------------------------------------------------
' This checks if the connection is fake,
'----------------------------------------------------
For sockmatck = 0 To sckConnection.UBound '2
If FakeSocket(sockmatck).SocketIndex = index Then
If FakeSocket(sockmatck).IsitFake = True Then
FakeSocket(sockmatck).IsitFake = False
GoTo BreakLoop
End If
End If
Next sockmatck
'----------------------------------------------------
'Finding the user that connected to socket index
'----------------------------------------------------
If index = 0 Then
Static_Accounts(Zero_Case_Array_Slot).IsConnected = False
Static_Accounts(Zero_Case_Array_Slot).IsAlphaConnected = False
' This is for ping, checking pings is currently disabled in server
Ping_Track_Array(index).IsIdle = False
GoTo BreakLoop
End If
For sockmatck = 0 To G_Array_Size '2
If StaticAccountIndexMatch(sockmatck).trackindex = index Then
temp = StaticAccountIndexMatch(sockmatck).ArrayIndex
Static_Accounts(temp).IsConnected = False
Static_Accounts(temp).IsAlphaConnected = False
Ping_Track_Array(index).IsIdle = False
GoTo BreakLoop
End If
Next sockmatck
'-----------------------------
BreakLoop:
' close the socket
sckConnection(index).Close
' set the properties
m_ActiveConn = m_ActiveConn - 1
' raise the event
RaiseEvent LostConnection(index)
End Sub
I am using Will Barden's Winsock Array control ( http://www.winsockvb.com ) as a base, many thanks to him from here.
This code as I said works normal usually, but sometimes it fails to close a connection.
I didnt implement Squidge's suggestion to the client side, because users may not exit the client safely always. So I thought that it is not a safe method to close a connection ? Am I wrong?
I think I am assuming smtg wrong, Thanks all for helping.
EpcH
Squidge
03-31-2003, 12:38 PM
hi, how about removeing, the close button from the top of the form by setting controlbox to false
then adding a quit command whith the code something like.....
winsock.senddata "///E"
'then close the program....
also i think there is a command so like when the program ends eg - if end then .... but i dont know what.. lol :huh:
hopw it helps
After a second thought, maybe as you suggested I can handle the situation by closing the connection from "Form Unload" event or smtg from client's side :)
And one more question, related to this, unloading a form , or closing the client when the connection is IDLE with the server then does not always close the connection from the client's side right?
EpcH
PS: I checked my client code, and realized that I am not closing the client's socket before the user exits the program.
At the client's side, it seems that I used:
Unload frmMain
and sometimes just ...
End
Do "Unload" and "End" close the connection? , can it be the reason of my problem?
Thanks for everyone.
mikestar
04-02-2003, 02:10 AM
i have the same problem. somehow the server's winsock_close event doesn't seem to fire whenever the client closes the connection. i have already developed a ping system to work around my problem but i still want to understand why my problem exists anyway. i used to monitor the server winsock's state using a timer to determine connection states but it doesn't work well so i was forced to use a ping system.
I modified my client software and it seems to be working. But if the internet connection at the client's side cuts of, clients may still remain connected.
And for this, I think we need to use pinging. Seriously is there any bug or smtg known about the issue?
Any comments from experts may be very useful, I am reading the forums, find some similiar topics but they the ones I found were not giving enough information about the subject.
Thanks All,
EpcH
piggybank1974
04-03-2003, 07:30 AM
when the client closes their connection, lets say they send data to the server about their disconnection don't forget to place the DoEvents directly after the winsock sendData method or it will not work before you close the app or form.
the pig..