Results 1 to 40 of 48

Thread: Winsock & Multithreading with Activex EXE

Hybrid View

  1. #1
    Member
    Join Date
    Apr 2005
    Posts
    39

    Re: Winsock & Multithreading with Activex EXE

    Hi CVMichael, based on my personal experience with Winsock Control and MultiThread in VB6, I think there are 2 issures need to be considered.
    1. how to dynamically connect winsock events handlers?
    2. can't pass requestID
    Second one seems to be impossile. How about the first concern? Any ideas? Thanks.

  2. #2

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: Winsock & Multithreading with Activex EXE

    Quote Originally Posted by ordnance
    1. how to dynamically connect winsock events handlers?
    I'm not sure what you mean, can you explain a little ?

    I attached a picture of how the multithreading model looks like (for my application). If you notice in my example there are 4 clients conected, and there are 5 threads. That is because there is always one thread that is listeing for a new connection, when a new client connects it stops listening, and it raises an event to the main Server EXE to create a new Thread that will listen for a new connection, and so on...
    Attached Images Attached Images  

  3. #3
    Member
    Join Date
    Apr 2005
    Posts
    39

    Re: Winsock & Multithreading with Activex EXE

    Quote Originally Posted by CVMichael
    Originally Posted by ordnance
    1. how to dynamically connect winsock events handlers?
    Well, actually I'm a newbie of VB for only a couple of weeks. I am sometimes lack of ideas in how VB programmers handle a particular issue. So sorry for not giving you a clear idea.

    After reading your graph, I fully understand how you are going to do. It is workable. Please ignore my questions because now I think they are not smart. Thans for your instructions.

  4. #4
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Re: Winsock & Multithreading with Activex EXE

    This is exactly what I have for a server app.

    Have you looked at my "multithreading" code?
    I use this to communicate between the connections running in a seperate process and my server app.

    When a connection is requested I accept the connection, and tell the server app it's been accepted (viaa my multithreading gateway code). The server then spawns another connection that listens.

    woka

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: Winsock & Multithreading with Activex EXE

    Hi Wokawidget, I did not look at your code, and I don't think I will, I did it before, and I got scared You use WAY to many classes/objects/files, etc. I don't want to go through that again

    I read the comments in the thread where you describe the code, and I got an idea on how you did it.

    The way I did mine is like this:

    Thread (ActiveX EXE):
    ----------------
    1) A form where I put a timer, and a Winsock, both of them raise events to the thread class
    2) The thread class, that raises events for ANY changes in data that Main EXE needs (i.e. Client info/status, connection status, database connection status)

    Main EXE:
    ----------------
    1) A UserControl that creates one Thread, receives it's events, stores the info, and raises/forwards events to main EXE
    2) Main form, has a control array of the UserControl (This way I treat the UserControl as if it was a Thread, except I can call functions/subs from it even when the real thread is busy with something)



    Also, I re-use threads (same as winsock array), when I get an event from the thread to create another thread (because current one is not listening anymore), I actually search through the UserControl array to find wich thread is not doing anything (not connected to a client), and THEN I call a funtion in that thread telling it to listen.
    If all threads are busy then I create a new thread. (As I was saying same as winsock array)

  6. #6
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Re: Winsock & Multithreading with Activex EXE

    Can you post a snippet of code on how you loop through all the connections and test to see if they are not connected...
    Is it something like:
    VB Code:
    1. 'modular level var
    2. Private mcolItems As Collection
    3.  
    4. 'code in function
    5. Dim objConn As SckConnection
    6.    For Each objConn In mcolItems
    7.       If objConn.IsConnected Then
    8.          'code to connect objconn
    9.       End If
    10.    Next objConn
    Is it something like the above?

    Woka

  7. #7

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: Winsock & Multithreading with Activex EXE

    This is the actual code in my app...

    CConnection is the usercontrol that makes the thread
    VB Code:
    1. Private Sub CConnection_MakeNewThread(Index As Integer)
    2.     Dim K As Long, clsErr As clsReturnError, Listening As Boolean
    3.    
    4.     LoadDBSettings
    5.    
    6.     For K = 0 To CConnection.UBound
    7.         If CConnection(K).ClientSocketState = sckListening Then
    8.             Listening = True
    9.             Exit For
    10.         End If
    11.     Next K
    12.    
    13.     If Not Listening Then
    14.         For K = 0 To CConnection.UBound
    15.             If CConnection(K).ClientSocketState = sckClosed Then Exit For
    16.         Next K
    17.        
    18.         If K = CConnection.UBound + 1 Then Load CConnection(K)
    19.        
    20.         Set clsErr = CConnection(K).StartThread(TCP_LocalPort, m_DatabaseName, m_DriverStr, m_UserName, m_Password)
    21.     End If
    22. End Sub
    As you can see it creates a new thread ONLY when ALL threads are used, otherwise it will start the thread that has a closed connection
    Last edited by CVMichael; Apr 26th, 2005 at 11:12 PM.

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