Using my SimpleServer class, the socket instances are hard coded in the "Declarations" section of the calling program using the "Implements" function.
Code:
Const Max_Connect As Long = 5
Implements SimpleServer
Private mServer(0 To Max_Connect) As New SimpleServer
I would like to allow the user to configure the Maximum Connections without having to recompile. Is this possible? VB help isn't much use, as it says "The Implements statement can't appear in a standard module".
Why the constant must to be 5 and not other values, like 10?
The Const Max_Connect and mServer() declarations are not part of the Implements, so they can be clanged to:
Code:
Private Max_Connect As Long
Private Const Max_Connect_Default as Long = 5
Implements SimpleServer
Private mServer() As New SimpleServer
Private Sub Form_Load() ' Or Class_Initialize()
MaxConnect = Max_Connect_Default
End Sub
Pulic Property Let MaxConnect(nValue as Long)
If nValue <> Max_Connect Then
Max_Connect = nValue
' Code to finish running objects
Redim Preserve mServer(Max_Connect)
' Code to create new objects
End If
End Property
But perhaps I'm not understanding what you are asking.
"Implements" statements declare that this module (which must be an object module such as Class, Form, UserControl, etc.) implements a secondary interface. Static "standard" modules cannot implement any interfaces because they are not object definitions.
What make you think you want to use Implements here?
But I admit I am also clueless. Why not just have a MaxConnections property?
I don't fully understand how or why it works, but the help of Bonnie West I was able to create multiple instances of a class while supporting Events (see following thread). WithEvents doesn't work with Object Arrays.
To do this, I am assuming that the instances have to be declared in the Declarations section in order to create the Events for each instance. 5 is an arbitrary number that I used for development (1 listening socket and 5 connection sockets), but what I would like to do is allow the user to declare as many sockets as he/she requires. I will play around with Eduardo-'s suggestion a little.
Eduardo-'s suggestion does seem to work. I have adjusted the sample code in post #2 in the above link to allow the user to input the maximum connections.
I made a sample project with a suggestion in the case you want to change the interface from using Implements to using WithEvents in your SimpleServer class.
In the first sample the user must supply an additional parameter "key" when creating a new socket, that key is used to identify the instance.
I don't know if it would be better to automatically generate the keys, so there is a second sample that does that.
It has a cSimpleEvents class object instance that both objects, SimpleServer and each instance of SimpleSock have to send the events from one to another.
It is a way to have WintEvents in collections.
Last edited by Eduardo-; May 7th, 2017 at 11:02 PM.