Hi,
I'm having trouble creating a collection of Sockets, using the Winsock active-x control.
Can someone show me how to create a new instance of a socket, add it to the collection, and use the sockets events
thanks!
Printable View
Hi,
I'm having trouble creating a collection of Sockets, using the Winsock active-x control.
Can someone show me how to create a new instance of a socket, add it to the collection, and use the sockets events
thanks!
Show me what you've tried so I can show you where to go.
Well I'd like to create instances, as I do with Class modules:
private withevents sckSocket as winsock
Set sckSocket = new winsock
But it won't let me. If anyone can give an example of how to maintain a collection of Winsock sockets, please let me know!
In fact I think I'll just use the clsWinsock class module and avoid the Active-x control. But I'm still interested how it can be acheived with the control.
Thanks
You may wanna look into DirectPlay as an alternative to Winsock. Seems to work a lot better, plus it's used on Massive Multiplayer Online games. That'll give you an idea on what I mean on working a lot better ;)
http://externalweb.exhedra.com/Direc...TUT_DX8_DP.asp
You'll have to add a refernce to MSWINSCK.OCX
Goto Project\References Browse to system32\MSWINSOCK.OCX
ThenVB Code:
Private WithEvents Winsock As MSWinsockLib.Winsock Set Winsock = New MSWinsockLib.Winsock
Since winsock is a control it must be added to Controls collection:
Set sckSocket = Form1.Controls.Add("ProgID", "new_name")
However, since Wisock IS NOT and Intrinsic control you must add a license to licenses collection ... so it's a pain ...
Instead of all those troubles use Control Array: create one instance of Winsock control in design, set Index = 0 so you can Load more instances at run time:
VB Code:
Load Winsock1(Winsock1.Ubound + 1) Winsock1(Winsock1.Ubound). ... 'use whatever methods/properties you need
Yea, thanks very much. I've done it with arrays before, but you have to scan them when re-using sockets and loading them etc. I just thought it would be easier to have a collection.
Thank you all.