I am attempting to create a TCPSocket that can have multiple connections in a manner that does not need to be associated to a Window and can be used anywhere in the app by a Window, Module or Class
Normally on a window I would drop a TCPSocket (Controller) then add Connected - DataAvailable - Error - SendComplete Event Handlers. Then add a control set and make sure the index was set to ‘0’. This would enable you to open a connection using a Member id such as ‘0’. This method requires that ‘window’ to be open
To start with I have created a class with Event Handlers. Then in App a property whose Type = the new class but I see no way to add a control set to enable multiple socket capability
Is there a better direction to travel or did I miss something implementing this new TCPSocket Class?
I think you are mixing yourself up with the semantics. You don’t want a TCPSocket that can have multiple connections… you want an instance of MultiTCPSocketController which happens to support X number of TCP connections.
Couple different ways you can handle this. You’ll be doing a lot of event handling and AddHandler’s. Knowing whether you are talking about 3 connections or 300 would change how I advise going about it. No need to overcomplicate!
Sounds like you simply want an array of type YourTCPSubclass. The shared event handlers are taken care of in the definition of your class. The only thing you’re missing is creating several of them. Create a global array and instantiate them as needed.
MyArrayOfSockets.Append New MyTCPSocketClass(MyArrayOfSockets.Ubound+1)
The argument to the socket subclass Constructor allows you to assign an ID.
Whoa, wait a second. Why are you not using a ServerSocket? That will manage the ports and the array of sockets for you automatically.
I got the impression these were outbound connections. ServerSocket would be the correct choice for inbound connections. Which is it, Carl?
Good questions. I just checked in a project and I am using a TCPSocket
and in the Control Set of the Inspector I assign this TCPSocket as a ‘Member Of’ and then set Index = 0.
In the editor it appears like this
There is an ‘index’ property that enables you to test - track and use specific connections such as ‘Connected(index)’ inside the Connected Event Handler of SCG_TCPSocket
#Tim - yes these are for outbound connections. This approach enables a proprietary internal communication method between several applications even when on different networks.
I implement the following
SCG_TCPSocket(curSocket).address = myaddress_str
SCG_TCPSocket(curSocket).port = myport
curSocket = curSocket + 1
This enables more than 1 TCPSocket connection
So this is an instance of TCPSocket dropped onto a Window from the ‘Controllers’ Library and I am looking to establish this SCG_TCPSocket programmatically
Does that make sense?
Do you create new sockets on the fly? Or do you create a preset number of them on the window?
#Tim: On the ‘server side’ I currently do a preset number however I would like to do this on the fly. I think that approach would be more flexible
#Greg: Good thought - not sure how to implement a ServerSocket programmatically that would enable testing connectivity - track and use specific connections
Ultimately I would like to enable a person with admin rights to be able to ‘group’ or ‘ungroup’ connections on the fly so communications will be shared between more than one or directed to just one. This will be a next step after this is working