Despite pouring through all kinds of knowledgebase information, example code, and forum threads, I have yet to find the root of the problem with my program. Before integrating the Datasocket features into my program, I tried to put together a quick demo to prove its capability, but I'm having trouble getting both sides of the two-way communication to work. I've seen a number of posts in which people theorize that two-way communication should just be as simple as adding a second Datasocket connection for the second data path, but countless attempts to get my demo program to work have failed...
Attached is my simple demo program. The summary of its operation is as follows: Program "1" is run on one PC at 172.16.168.1 and program "2" is run on a second PC at 172.16.168.4. Ideally, clicking the "Send Packet" button on the program 1 GUI sends the program into that button's callback, which initiates a sequence in which it sends a packet of data via a Datasocket connection to the other PC. Meanwhile, the other PC's program has been running through a loop waiting for non-zero data via that Datasocket connection. Once it sees non-zero data, it jumps out of the loop, does some data processing, and basically sends back the same exact data via a second Datasocket connection. Back at the first PC, the program has transitioned from sending that first data packet to a loop awaiting the return data via the second Datasocket connection. Once it sees the non-zero data, it stores the data. At the end, zeros are sent to the second PC as a sort of confirmation that everything worked, at which time the second PC sends back zeros as a final confirmation.
Depending upon how the programs are run, the symptoms change...
1. If I set the IP addresses of each Datasocket connection to "localhost" (or 172.16.168.1) and run both programs on the very same computer, everything works perfectly!
2. If I leave the program as it was originally written and run program 1 before program 2: The first data packet is sent, program 2 receives it, processes it, and sends it back via the second Datasocket connection, but program 1 remains in the "read" loop and never sees non-zero data being returned.
3. If I leave the program as it was originally written and run program 2 before program 1: The first data packet is sent, but this time program 2 remains in its first "read" loop and never sees non-zero data being sent.
Thinking that this must be a timing issue, I've played with delays and other ways of ensuring that the events happen in the "ideal" order. I've also tried removing the ProcessSystemEvents() calls to ensure that the callbacks aren't "restarted" at inappropriate times. I've tried different combinations of IP addresses for the various DS_Open() calls to see if the computer that each connection is established on is critical. I've tried a million things, but can't seem to figure out why the programs get into situations where they just don't see the new, non-zero data. I've also swapped the programs between the two computers to ensure that it's not a computer-specific problem.
Any thoughts?