|
-
November 10th, 2002, 12:40 AM
#1
Killing the bad Winsock Connections
I made a chat server where multiple people can connect. They all connect on the same port but through an array (so there are no conflicts). As clients connect, their names are added to a listbox. Problem is when they disconnect. Sometimes my program doesn't delete their name from the list and thinks the client is still 'alive', when infact they are gone.
The refresh for winsock.state is 10 ms (meaning it loops through all the connections on the list and deletes bad connections every 10 ms). Unfortunately, this doesn't work all the time. Some say I should ping the clients, but that would interfere with the data being sent across that port. Does anyone have any other ideas?
-
November 10th, 2002, 04:18 PM
#2
Dear IMasterXX,
You can use the select-call (--> MSDN), which tells you if a client has disconnected or was being disconnected (e.g. system crashed).
The select function is able to do more than this, but it's description in the MSDN is detailed enough.
PeterZ
-
November 10th, 2002, 11:07 PM
#3
Regarding the case select with Winsock...
I tried the case select for winsock:
Select Case Winsock1(ConnectedUsers(socketcheck)).State
Case 0
'Status.SimpleText = "Closed"
Case 1
'Status.SimpleText = "Open"
Case 2
'Status.SimpleText = "Listening"
Case 3
'Status.SimpleText = "ConnectionPending"
Case 4
etc...
and when there's an error, the user is removed from the listbox. this case select is executed every 10ms but some users will stay in the listbox and will not be removed even when they disconnect. any way to fix this? :-(
-
November 11th, 2002, 05:35 AM
#4
Dear IMasterXX,
the default socket-implementation (Berkeley-sockets) knows a function called listen this function has some parameters, lists of sockets. And checks if a socket is connected to a client or not, you can also check if a read, accept, ... a.s.o. will block or if there is data available.
I don't know the VB implementation of sockets, if it is a winsock implementation there should be that call too.
PeterZ
-
November 13th, 2002, 06:20 PM
#5
problem with built-in functions...
Winsock has the function error(). So if I wanted to close a connection when an error occurs, I would use that function. But the function doesn't detect an error right away. It only detects an error after i try sending data to the disconnected user. So while I'm away from the computer, my program might be adding the same people to the listbox, even though the prior connections aren't 'alive'. There must be some way to detect if an error occured.
-
November 14th, 2002, 02:32 AM
#6
Dear IMasterXX,
you can use the property SocketHandle to get the sockethandle, this handle can be used with a API call to select
int select(
int nfds,
fd_set FAR *readfds,
fd_set FAR *writefds,
fd_set FAR *exceptfds,
const struct timeval FAR *timeout
);
Summary: A socket will be identified in a particular set when select returns if:
readfds:
If listen has been called and a connection is pending, accept will succeed.
Data is available for reading (includes OOB data if SO_OOBINLINE is enabled).
Connection has been closed/reset/terminated.
writefds:
If processing a connect call (nonblocking), connection has succeeded.
Data can be sent.
exceptfds:
If processing a connect call (nonblocking), connection attempt failed.
OOB data is available for reading (only if SO_OOBINLINE is disabled).
PeterZ
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|