I am having problems with using the same TCP connection among different programs. Essentially I have a main program that opens the connection and I share the connection ID as a global variable. This is to facilitate various sub-procedures that will need to send data over this connection (one at a time). To help illustrate this, the main program is the top layer (layer one), and the sub-program (layer two) which uses the connection to communicate with the final simulation layer (layer three).
The problem is that it appears to matter where this connection is initialized. That is, if I do it in the main program, and call the global variable from the sub-program, then it doesn't work (properly). However, if the same code is moved in the sub-program, and the global variable is called within the same sub-program, then all works wonderfully.
This leads me to believe that it is not a matter of the global variable. I'll post the connection code. Any advice/ideas would be appreciated.