Error #75 at Open {file} For Input As #1 (need 2 progs on same PC to communicate) - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1) +--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3) +---- Forum: Help Me! (https://qb64phoenix.com/forum/forumdisplay.php?fid=10) +---- Thread: Error #75 at Open {file} For Input As #1 (need 2 progs on same PC to communicate) (/showthread.php?tid=2726) Pages:
1
2
|
RE: Error #75 at Open {file} For Input As #1 (need 2 progs on same PC to communicate) - madscijr - 05-23-2024 (05-23-2024, 07:25 PM)Steffan-68 Wrote: I might have another thought.Interesting idea... Maybe we can try that later. For now I have it working with DSMan195276's network code. (Will post soon in Works in Progress.) RE: Error #75 at Open {file} For Input As #1 (need 2 progs on same PC to communicate) - SMcNeill - 05-23-2024 (05-23-2024, 06:56 PM)DSMan195276 Wrote:(05-23-2024, 05:45 PM)Kernelpanic Wrote: One could almost compare it with a traffic light at an intersection: If North - South is green, then West - East has to wait (red) until it itself is green. If all road users stick to it, there won't be crashed.Unfortunately Steve's approach can't prevent both programs from reading and writing at the same time, I don't think there's a way to do it with read/write file interactions alone..... It can. Try these two programs out and watch them interact with a single file: Code: (Select All)
Code: (Select All)
They set the flag for who has control, and skip doing anything unless they have control... Then when they're finished writing, they set the flag so the other program now has control to read. Note that you can also use LOCK to make certain that only one program can access a file at a time, though I didn't mention it earlier as it's WINDOWS ONLY. https://qb64phoenix.com/qb64wiki/index.php/LOCK RE: Error #75 at Open {file} For Input As #1 (need 2 progs on same PC to communicate) - Kernelpanic - 05-23-2024 This now reminds me of MySQL and PostgreSQL; that I once had to do with. The file that is currently being written to must of course be locked for other write access. . . otherwise there would be breakage. This is all very complicated. And therefore very error-prone. @madscijr, check the design of your program again. RE: Error #75 at Open {file} For Input As #1 (need 2 progs on same PC to communicate) - madscijr - 05-23-2024 (05-23-2024, 08:30 PM)Kernelpanic Wrote: This now reminds me of MySQL and PostgreSQL; that I once had to do with. The file that is currently being written to must of course be locked for other write access. . . otherwise there would be breakage.Yup, it was a terrible kludge! The latest version in WIP now uses DSMAN's network code, seems to be working better. RE: Error #75 at Open {file} For Input As #1 (need 2 progs on same PC to communicate) - DSMan195276 - 05-23-2024 (05-23-2024, 08:09 PM)SMcNeill Wrote: They set the flag for who has control, and skip doing anything unless they have control... Then when they're finished writing, they set the flag so the other program now has control to read.I mean you didn't really solve the underlying problem, you simply avoided the race by adding a _Delay .1 That said, one-way commutation with three states like you're doing has some potential. I'd still be concerned about caching, especially on Linux and Mac OS where we make use of the C++ file streams, but overall I think it's ok. RE: Error #75 at Open {file} For Input As #1 (need 2 progs on same PC to communicate) - madscijr - 05-23-2024 (05-23-2024, 10:05 PM)DSMan195276 Wrote:If two programs could share the memory pointers for certain variables, that would be the fastest communication. Of course that opens up other problems, but if it was a bona-fide feature built into and managed by QB64PE, kind of like shared global variables - super global variables, ie shared across 2 or more processes, that might be kinda useful! I'm nowhere near as technical or knowledgable as the other folks here, so it's entirely possible it's not possible or a Bad Idea, but I figure it's worth asking about...(05-23-2024, 08:09 PM)SMcNeill Wrote: They set the flag for who has control, and skip doing anything unless they have control... Then when they're finished writing, they set the flag so the other program now has control to read.I mean you didn't really solve the underlying problem, you simply avoided the race by adding a _Delay .1 RE: Error #75 at Open {file} For Input As #1 (need 2 progs on same PC to communicate) - SMcNeill - 05-24-2024 (05-23-2024, 10:05 PM)DSMan195276 Wrote:You can skip that delay completely and the flag system will still work. The programs just take turns working with the file.(05-23-2024, 08:09 PM)SMcNeill Wrote: They set the flag for who has control, and skip doing anything unless they have control... Then when they're finished writing, they set the flag so the other program now has control to read.I mean you didn't really solve the underlying problem, you simply avoided the race by adding a _Delay .1 Program 1 starts up. Creates file. Sets flag for "In use." Writes to file. Program 2 starts up. File exists. Checks flag. It's in use... does nothing. Program 1 finishes writing. Sets flag for "Hey you, read this!"... It now enters standby mode. Program 2 sees flag. Reads file.. Program 1... File still flagged for program 2 use... wait... Program 2 finishes reading file. Now writes whatever data it needs to send back. Program 1... File still flagged for program 2 use... wait.... Program 2 finishes writing to file. Now sets flag to "Hey, Program 1, it's your turn!" Program 1... Reads flag... Takes control... BINARY lets you read and write at the same time. As long as the first byte in the file is set, you can toggle that back and forth to pass control to whichever program gets to use the file at any given time. May wear your drive out toggling that one byte over and over and over again, but it's quite doable. Even with caching, it wouldn't matter, as the control remains with the other program until that cache catches up and updates... though if your cache doesn't push to file for a while, you may end up with both program just being locked in a waiting state until that write finally occurs. And with that said, I still think the easiest way to do things would be to just OPEN "localhost" for TCP/IP and PUT/GET info back and forth like that between the two programs. RE: Error #75 at Open {file} For Input As #1 (need 2 progs on same PC to communicate) - madscijr - 05-24-2024 (05-24-2024, 12:56 AM)SMcNeill Wrote:(05-23-2024, 10:05 PM)DSMan195276 Wrote:You can skip that delay completely and the flag system will still work. The programs just take turns working with the file.(05-23-2024, 08:09 PM)SMcNeill Wrote: They set the flag for who has control, and skip doing anything unless they have control... Then when they're finished writing, they set the flag so the other program now has control to read.I mean you didn't really solve the underlying problem, you simply avoided the race by adding a _Delay .1 Yikes... That all seems a little too "bare metal" for comfort, lol. I'm sure it could work, the TCP/IP method just seems a lot cleaner, nice and simple! What about shared variables in memory? One program could use TCP/IP to pass a pointer to the address of the variable to the other EXE, and as long as both of them always write a fixed anount of bytes to it, they could swap values back and forth. It's also kind of low level, I'm just curious if it would perform any faster than pure TCP/IP... RE: Error #75 at Open {file} For Input As #1 (need 2 progs on same PC to communicate) - DSMan195276 - 05-24-2024 (05-24-2024, 12:56 AM)SMcNeill Wrote: You can skip that delay completely and the flag system will still work. The programs just take turns working with the file.The issue is writefile, both programs call it when the status is zero. Imagine this flow: Program 1 calls Checkfile, sees zero. Calls writefile Program 2 calls checkFile, sees zero. Calls writefile Program 2 calls Put #1 with 22 Program 2 calls Get #1, sees 22, continues Program 1 calls Put #1 with 12 Program 1 calls Get #1, sees 12, continues At this point, both programs have continued in writefile and are writing to the file at the same time. The delay effectively prevents this situation simply because the actual code in writefile takes less than .1 seconds to finish writing to the file. Even when both programs enter writefile, the delay means program 1 can't actually start writing until well after program 2 is done. Caching can be a problem in the same situation, the program might not reread the status code from the file when you do the `Get`. In that situation the order doesn't matter, if they both call `writefile` then they both write to the file because they don't see eachother's status updates (and then like you said, get locked up as they won't see the status to read). |