-
Hello World,
I'm trying to use the following code to build a client-server app (cleaned up the code a bit/lot). Works fine till now, But.....
I want to make the client connect to multiple servers.
So best thing to do (I Think) is make one collection of the client-objects, where the different servers will call back upon.
Can anyone help me with this code, coz I don't seem to get it right?
If you want the full example I used please let me know & i'll mail it to you.
GREETINX,
Don
CLIENT-vbp :
form :
Code:
Dim objCbSvr As Object
Dim objMyClassInstance As Object
Private Sub cmdconnect_Click
Set objMyClassInstance = New CbClientProj.CbClientClass
Set objCbSvr = CreateObject("CbServerProj.CbServerClass")
if objCbSvr.AddObjectReference(objMyClassInstance) Then
objCbSvr.MyServerMethode(test)
end if
end sub
Private Sub cmddisconnect_Click
If objCbSvr.DropObjectReference(objMyClassInstance) Then
Set objMyClassInstance = Nothing
Set objCbSvr = Nothing
end if
end sub
class:
Code:
Private Sub Class_Terminate()
Debug.Print "CbClientProj.CbClientClass Terminated."
End Sub
Private Sub Class_Initialize()
Debug.Print "CbClientProj.CbClientClass Initialized."
End Sub
Public Sub MyclientSub(test As String)
'This is the *public* method the server calls (-back onto)
'more code
End Sub
SERVER-vbp :
module:
Code:
Global gObjRef As Object
class:
Code:
Private Sub Class_Terminate()
' Debug.Print "CbServerProj.CbServerClass has terminated"
End Sub
Private Sub Class_Initialize()
' Debug.Print "CbServerProj.CbServerClass has intialized"
End Sub
Public Function AddObjectReference(Caller As Object) As Boolean
Set gObjRef = Caller
AddObjectReference = True
End Function
Public Function DropObjectReference(Caller As Object) As Boolean
If gObjRef Is Caller Then
DropObjectReference = True
Else
' Debug.Print "Caller not the same as ObjRef. Unable to quit."
DropObjectReference = False
End If
End Function
Public sub MyServermethode(test)
'more code on server which later on triggers following code
gObjRef.MyclientSub (serverdata)
End Sub
-
Would it not be easier to simply make an array of client objects, one for each server?
-
Hmm,
Don't know for sure but i think an array is 1 object, so the server has to know the number of the array also.
when using a collection the server probably calls onto collection using the correct key.
Don't think this matters a lot.
still preffering the collection (easier to handle), i'm trying things to solve this meanwhile
thanks for the input, Joacim.
by the way the client is actually the master-server which fills the database with info from all the other servers.