Basic Array Help

If i was to make a socket array like

Dim Sockets(1000) as socket


Then in form_load i put

For a as integer = 1 to 1000
sockets(a) = new socket
next a


How would i go about handling when it connects and stuff



Answer this question

Basic Array Help

  • Jacob Grass

    That's really not the way to go for socket handling (It was done that way in VB6 because that was pretty much the most reliable way to do it - not so in .NET).

    As Renee said, you can create a thread pool, and have the threads handle everything (or start with a simpler approach, and have a thread listener, creates a new thread each time that a client requests a connection). Even so, which 'events' for the 'socket' are you wanting to hook up (the socket doesn't have events, that I can see).

    I would say look at the TcpClient and TcpListener class. They are much easier to use, and provide almost all the functionality you would need.



  • Dan Mikkelsen

    Okay, I'm posting this because I'm 99% sure I've seen code that does what you want. I was surprised because I thought it couldn't be done either.

    I'm pretty sure that vb express treats everything as objects, you have to assign the array using a directive in the declares. Try lookin at declarations in your msdn.

    I wish I could be more help, I've tried finding it again but I've been to so many sites and forums today that I simply cannot remember where it was. If I come across it again I'll post the link in this thread.

    Anyway, keep trying and post the answer if you find it, and if I'm wrong and you really can't have arrays of that type then I'll appologise now, lol.



  • spiovesan

    I don't think you'd want to do that. I do think you'd want to create a thread pool with connections and use then as needed.



  • roy-roy

  • Mohican

    I dont get that


  • Basic Array Help