DLL & COM & ActiveX: Winsock in UserControl

  • bshadow / 104 / Sun, 31 Jan 2010 03:16:00 GMT / Comments (7)
  • Hello,

    I'm working on a FXP program. For this, I've created an ActiveX control. On this control I've placed two Winsock Controls. One to connect with to the FTP server, and one to listen for incomming connections for the LIST function.

    Okay, my application creates more than one form on which this control is placed. So, if it should connect to two FTP servers, dynamically two forms are loaded from one form.

    Dim Server as Form
    Set Server = New frmServer
    'Here the form is created

    The form starts my control by setting the remote server parameters like IP username etc. and then calls the custom connect method.

    When connecting to just one FTP server, everything works OK, but when a second one is loaded, the first one just shows the welcom messages and it just looks like the control is not doing any actions. The second control (on the second from) is connecting and logging in as the first one. Now I'm usign classes for saving those server properties and the username is set correct for the first and second control. So it just looks like the second control is taking over the first one and logging in...

    please help me out here, I have no idea what is happening here. I've checked if the control is indeed initialized twice, and that is the case. The username etc. are added to the class collections, so this is OK too. Or so I think.

    I know Winsock can 'lose' some data when not using the DoEvents, but I use it after every Winsock command like SendData, Close etc.

    I hope anyone can help me out here...
    Thx in advance.
  • Keywords:

    winsock, usercontrol, dll, com, activex

  • http://programming.itags.org/com-activex/174553/«« Last Thread - Next Thread »»
    1. *bump*

      bshadow | Wed, 05 Dec 2007 13:39:00 GMT |

    2. looks like your controls are actually fighting for the same port... (the latest one wins :D ). the way that you done it is not exactly appropriate. microsoft says to try this:

      Private intMax As Long

      Private Sub Form_Load()
      intMax = 0
      sckServer(0).LocalPort = 1001
      sckServer(0).Listen
      End Sub

      Private Sub sckServer_ConnectionRequest _
      (Index As Integer, ByVal requestID As Long)
      If Index = 0 Then
      intMax = intMax + 1
      Load sckServer(intMax)
      sckServer(intMax).LocalPort = 0
      sckServer(intMax).Accept requestID
      Load txtData(intMax)
      End If
      End Sub

      what youre doing is you open a control array (so make sure you manually set index 0 for your winsock control, to make it an array). only the control with index 0 'listens' for connections, and as soon as a connection request is received, it 'spawns' a new instance of the control that takes over the data handling. i know this doesnt fit the architecture that you have right now, but at least it gives you the idea. also, as you may have noticed, this code constantly increases the size of your array (not a problem for microsoft, as you know), so you may wanna reuse connections that have been closed by peers.

      and a final question: can't you use the standard microsoft internet transfer control for your ftp stuff? not that it wont give you any additional headaches, but at least you get rid of the low-level stuff.

      radum | Wed, 05 Dec 2007 13:40:00 GMT |

    3. Thank you for your reply. I am familiar with your solution and have used it before. However this application can not use such a way to connect.

      First the local port is set randomly and a PORT commando is send to the FTP server. The chance of two controls having the same port is very small, and if so, the chance of this occuring everytime I start the app, is even smaller, so I don't think this is the problem. However, you said the last one wins and this should occur when they DO listen on the same port. Therefore I think the spawning of the controls is not quite as I thought it would be. Maybe every instance is actually the same, so when setting the local port of one, I am actually setting the remote port of all...

      I spawn my controls at runtime giving them an index and using the load function.

      I still think this problem is ActiveX related... Somehow.

      bshadow | Wed, 05 Dec 2007 13:41:00 GMT |

    4. man, this is at least very weird. imho, having winsocks in separate instances of activex objects, having activex objects loaded on separate forms - this offers a quite serious degree of isolation between the original winsocks, so i dont think you have a problem at that level. rather, for me the problem seems to be that the primary winsocks, somehow, refer eventually to the same port and theyre bothering eachother. by the way your frustration sounds, i assume that you already checked the properties that the controls end up with on each form, but i would say this is the area where you have to insist... i'm sorry, i dont understand your app very well (sounds like youre somehow an ftp server...?). good luck.

      r

      radum | Wed, 05 Dec 2007 13:42:00 GMT |

    5. Radum, thank you.

      You are right, I'm making an FTP / FXP client actually. And yes I have checked the local ports of the controls.

      I must say that I don't have concrete evidence for my thinking what the problem may be, but what I think is that when you put a winsock in a ActivX control, and use this control multiple times, the connection gets 'frustrated'. It's like there are to many 'DoEvents' in the code.

      I can not explain it more...

      Anyway, thank you very much in taking the time to discuss this. I have used another way to make my app, not using any usercontrols, just the winsock directly. Although I am still interested in a solution for this problem. May be the solution lies in the way Winsock behaves. May be I should use the Winsock API in the usercontrol... :)

      Thanks again...

      bshadow | Wed, 05 Dec 2007 13:43:00 GMT |

    6. wait a minute... you say youre doing 'doevents' in the dataarrival event?? one single word: DONT. what happens is that, if you yield control, your app may generate another dataarrival event, and at this stage you definitely messed up lots of your variables. it's the easiest way to loose control over your data stream, and i have a feeling this is what happens in your case.

      in my experience, a dataarrival chunk should be treated in one single 'gulp', or blocking operation. blocking doesnt necessarily mean 'bad': youre blocking at your application (read thread) level, but windows is smart enough to take care of the rest of the apps running on your computer and give them time chunks for processing. this is what a true multitasking is. dont be affraid to block with your app, and dont overreact with 'doevents' - just do your job and leave the others waiting.

      r

      radum | Wed, 05 Dec 2007 13:44:00 GMT |

    7. radum, thank you very much for replying. It seems I did not get an e-mail notification about your reply, so I'm sorry to get back so late.

      I'm actually still having the same problem, but I could try not using anymore DoEvents.

      I'm wondering if this does not compromise the other connections for multiple are established. Maybe I should put this in a multithread? Hmm, new options, I like it ;)

      Thx, I'll get back on you about this.

      bshadow | Wed, 05 Dec 2007 13:45:00 GMT |

  • DLL & COM & ActiveX Questions

    • VB with OOP

      Hi Where do I found examples using insert,update,delete, select , but that the app to be OOP , wi...

      By mutley, 1 Comments

    • what is wrong in this code?

      i am useing class and i write this code'*************************Public Sub HOSPLIST(FRM As For...

      By sal1150, 2 Comments

    • webbrowser

      Hello, Is there any one can tell me where can I find Webbrowser ocx that includes the features ofInt...

      By bmarzouk, 1 Comments

    • Windows XP SP2 Firewall issues with ActiveX

      Our web application (that gets installed on a client's network server) has a few activeX contro...

      By greg_quinn, 4 Comments

    • how to?

      hai alli am developing an application in DCOM. i have an activex dll which contains around 200 class...

      By needhelp, 3 Comments

    • What is COM?

      I am very confused about all these knew technologies . . . Could somebody answer my questions?- What...

      By jon_davis24, 3 Comments

    • Vb And Excel File ( read a1 cell val )

      I need help . ( who doesn't..)how can i do this thing:through vb app.open an excel document and...

      By daylor, 1 Comments

    • Very Easy to send E-mail

      http://vbs.8k.com/banner.gifUse This Active-X to send E-Mail(s)Use (Save target as)http://www.geocit...

      By prokhaled, 1 Comments