Author Topic: Multi Thread?  (Read 4901 times)

0 Members and 1 Guest are viewing this topic.

Offline brodie123

  • Newbie
  • Posts: 3
    • View Profile
Multi Thread?
« on: July 08, 2018, 09:54:23 pm »
Hi all.

I'm wondering if QB64 supports what I believe is multi-threading. 

i.e.

client&=_OPENCLIENT ("TCP/IP:23:#.#.#.#")
client2&=_OPENCLIENT ("TCP/IP:24:#.#.#.#")

If not, I guess I would open a 2nd client in another QB64 instance but is it possible to share variable values between 2 instances of QB64?

Either will work for me - any suggestions are appreciated.  I only need to share a single value but need to read 2 clients.

thx!



FellippeHeitor

  • Guest
Re: Multi Thread?
« Reply #1 on: July 08, 2018, 10:29:15 pm »
You can read multiple clients simultaneously.

Welcome to the forum!

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Multi Thread?
« Reply #2 on: July 08, 2018, 10:36:39 pm »
So kind of like a game where you have a host and 2 players? or just 2 players?
You can have a host program and multiple clients(players) connected and share data between them, through communications.
That's how my Monopoly game is set up, a host program and up to 8 clients and it communicates through IRC chat room chatter.

or if its all on the same machine you could just have a common data file open by both programs to share the values. Least I believe you can do that, I've never tried, having 2 programs open the same file that is.
Granted after becoming radioactive I only have a half-life!

FellippeHeitor

  • Guest
Re: Multi Thread?
« Reply #3 on: July 08, 2018, 10:40:49 pm »
Yes, two programs can have the same data file open (for binary or random access).

Offline brodie123

  • Newbie
  • Posts: 3
    • View Profile
Re: Multi Thread?
« Reply #4 on: July 09, 2018, 06:52:25 pm »
Thanks.

It's actually for an auto-helm for my boat that I wrote in QB64.  I have a separate 3rd party app that is the actual NAV sw where I plot my course and through the server port, sends the required compass direction for each next waypoint.  It uses the GPS to identify the current course heading however this has terrible lag - it calculates by measuring the current location, wait and then measure the location again giving you a 'fairly' accurate heading.  The lag causes the boat to sway.

I purchased a digital compass that reads the actual heading 20x a second, so no more lag.

I have a friend writing (in VB) an app to put the heading info into a data stream - so I need to know if QB64 can have 2 'clients' open at the same time. (I believe this is called multi threading)

The alternative is to write the data to an open file as I know QB64 can read open files - but is not a great way of doing it.

So can I have 2 client ports open at the same time as long as they are on different ports??

Thanks!!!!!!

FellippeHeitor

  • Guest
Re: Multi Thread?
« Reply #5 on: July 09, 2018, 07:25:44 pm »
An application can only have one host open per port (but multiple hosts open if using different ports).

Now, if you have an application working as host and want to connect to it, you can have as many clients as allowed by your system resources connect to that single host at the same time. If you want one single program to connect twice to the same host, just do as you indicated in your first post in this thread, opening the connection as client twice and storing the handle in two different variables.

Think of how a browser can open several tabs from the same website (same port for HTTP access) at once. It's the same logic here.

Offline brodie123

  • Newbie
  • Posts: 3
    • View Profile
Re: Multi Thread?
« Reply #6 on: July 09, 2018, 09:59:52 pm »
Awesome.  Thank you!!!


Offline Aureal

  • Newbie
  • Posts: 17
  • memes
    • View Profile
Re: Multi Thread?
« Reply #7 on: July 24, 2018, 04:27:04 am »
That is not multi-threading anyways, computers are very fast, even on single threads, so fast two tasks that run one after another seem to run simultaneously.
Real multi-threading is a different story, its about managing workloads the most efficient way possible.