Ok sports fans.
I am crying "Uncle" on this. I have tried to make a multithreaded VB6 chat server using the Winsock control. It works 99.9% (in other words, it doesn't work).
It multithreads beautifully, with everything in a single process. Something people seem to like to think "can't be done" in VB6.
Symptoms
Clients can connect, get a server thread of their own, and get a response from the server. Then it falls over.
The client gets a Close event almost immediately, which it of course shouldn't unless I have some bizarre error in the client. However the client is almost unmodified from a basic client I have successfully used many times with a regular single-threaded server.
Oddly, the server Winsock controls still seem to think they are connected!
I've added code to display the State after this has happened, and sure enough it comes back as 7 (sckConnected). With some playing around I was
on occasion getting an error in the worker threads' Winsock controls:
sckNotSocket 10038 The descriptor is not a socket
Guesses
I have come to the conclusion that either (a.) I have some bug I just can't see, or (b.) you can't Accept a requestID across
threads much more reliably than
processes!
Remember though, the server seems to successfully get a "greeting" message back to the clients after the Accept is done!!!
My guess is that the Accept actually works, but something on the order of a window message needs to come back to the listening socket to let it know the Accept actually happened (???). I tried Spy++ on the worker Form though and didn't see anything likely there in terms of messages.
Try It
To play with this, you need to compile both the server and the client, though the client can run from the IDE. Not the server though!
Also be sure to read the readme.txt for info on unregistering the server before each compile. This helps avoid registry clutter from creating new classIDs each compile (project has no compatibility).
Don't be afraid to use Task Manager to monitor the thread count of the server. As each client connects it should go up.