![]() |
TCP/IP. data from one program to another - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: Chatting and Socializing (https://qb64phoenix.com/forum/forumdisplay.php?fid=11) +--- Forum: General Discussion (https://qb64phoenix.com/forum/forumdisplay.php?fid=2) +--- Thread: TCP/IP. data from one program to another (/showthread.php?tid=3469) |
TCP/IP. data from one program to another - TheLastTMan - 02-16-2025 hi this is my first post. really if you want you can call me Abe, short for my real name. there is very little documentation about this and I have been experimenting on my own but have been having problems. i recently got interested in qb64 because it looks good more than anything else, i never used the original qb. since qb64 does not support multithreading i was looking at the wiki and i think tcp/ip might be the option. it would not be multithreading but multiprocessing but something is something. so i have this. Server.bas Code: (Select All)
Client.bas Code: (Select All)
apparently the part where I send the data works, but when I receive them in the client, something is wrong. I don't even know if the part where I manipulate the array is well done. I would like to know if you could help me to know what is wrong, I would accept any feedback, thanks. I don't know if I'm supposed to post this like this RE: TCP/IP. data from one program to another - bplus - 02-16-2025 @TheLastMan, Abe, what we are all women now? Ha! Welcome to the forum! I am, as yet, not interested in TCP/IP but it has been discussed many times here at the forum. Try a search if you tire waiting for someone to answer. Your post seems in just the right place to me. ![]() Update: here is quick link to most recent TCP/IP discussion: https://qb64phoenix.com/forum/showthread.php?tid=3101&pid=28986#pid28986 RE: TCP/IP. data from one program to another - NakedApe - 02-16-2025 Welcome, TheLastMan. Here's another good place to look. Steve's example of program to program hosting. https://qb64phoenix.com/forum/showthread.php?tid=2858&highlight=%22host%22 RE: TCP/IP. data from one program to another - DSMan195276 - 02-16-2025 The underlying problem is that `GET` does not wait for the data to arrive, if the client has not yet received enough data for your variable then it simply leaves the variable as-is and sets the EOF flag. Because of that, your `PUT` followed by an immediate `GET` of a LONG is very likely to fail because the other program won't have sent its response in time. You can check for this failure by checking `EOF(X)` after the `GET`, if it's set then that indicates the `GET` was unsuccessful. The simple solution is to just loop until `EOF()` is false, indicating you received the data. You should additionally check `_CONNECTED(X)` in the loop to determine whether the client was disconnected (you don't want to keep looping on `GET` if no data will ever come). On the `Server.bas` side of things it gets a bit trickier. The `GET`s` in there are unlikely to fail because the messages are currently very short, but you should still be checking `EOF()` and looping to ensure they're successfully received. That approach will be ok at a certain scale but it's not ideal because during the loop the server can't do anything else and you never really know if the client will send the rest of the message. There's a large variety of solutions to this issue, but I'd consider prefixing the messages with a length, that way you can have the main code wait until an entire message is received before you start processing it, then the rest of the code can simply handle the message without having to deal with the connection. RE: TCP/IP. data from one program to another - TheLastTMan - 02-16-2025 thanks, in other forums they are absurdly delicate with how you address yourself and how you write the post otherwise they almost banned you. i have bad experiences with that, people on the internet become wild very easily. RE: TCP/IP. data from one program to another - SMcNeill - 02-16-2025 https://qb64phoenix.com/forum/showthread.php?tid=2858 < Try this out and see if it helps. RE: TCP/IP. data from one program to another - mdijkens - 02-16-2025 I got the same need some time ago and have created this as a basis: tcp_server.bas: Code: (Select All)
tcp_clients.bas: Code: (Select All)
All client messages are sent to all other clients |