Results 1 to 3 of 3

Thread: I can't figure this out... weird Winsock problem.

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2004
    Posts
    9

    I can't figure this out... weird Winsock problem.

    Hi

    I have written a server program (VB6 SP6) which a number of client programs connect to. There is a strange error that keeps cropping up... but first I should explain roughly how the program works.

    There is a Winsock control (listening on Port 1000) that accepts incomming connections from client programs. When a connection is established, the server program creates a SingleUse instance of an ActiveX exe component.

    The ActiveX exe component sets its own Winsock control localport to 0, and then sets the Winsock control to listen. The ActiveX exe tells the server program what the new port is.

    The server program then tells the client program over the original Winsock connection which port the ActiveX exe is listening on.

    The client program closes it's Winsock connection and then connects to the ActiveX exe on the specified port. The server program then makes its Winsock control listen again on its default port (1000).

    ...so, when there are a number of clients connected, there are multiple instances of the ActiveX exe running, each on a unique port, and each sending events to the server program.

    When a connection is closed, the ActiveX exe is destroyed.

    This all works very well, but sometimes when a client program tries to establish a connection, an error occures. The client program connects to the server, gets the port, then when it tries to connect to the ActiveX exe on the new port, an error occurs in the ActiveX exe. 10022.

    According to MSDN, this means that the port socket was not closed when attempting to listen... but I have verified that the port is closed (state = 0).

    I have been struggling to find out what is going on for over two weeks. I would greatly appreciate some help with this as I'm on the verge of pulling my hair out!

  2. #2
    Addicted Member
    Join Date
    Mar 2006
    Posts
    178

    Re: I can't figure this out... weird Winsock problem.

    A bit hard to tell you what the problem is without seeing any sample code.

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2004
    Posts
    9

    Re: I can't figure this out... weird Winsock problem.

    Quote Originally Posted by davidbishton
    A bit hard to tell you what the problem is without seeing any sample code.
    Thanks for the reply. I think I might have figured out what the problem was after all this time. lol

    Before setting the Winsock to listen, I close the port to ensure its going to be ready... but it appears that it can take a while for it to completely close.

    I've put a loop which exits when the Winsock state = 0 (closed) or when it has been looping for 5 seconds.

    So far it appears to be working, but I need to do more extensive tests. If this hasn't resolved the problem, I'll come back here and post some code.

    Thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width