Big Question

Started by wadmixfm, May 08, 2023, 15:23:23

Previous topic - Next topic

wadmixfm

is it possible to run another program from my project and communicate with it ??

i.e

first program loads in data and then sends it to the second program

i know that blitzmax only focuses on the program at cursor selection but if the main program is running and sending data in the background all i need to do is send the program to the second monitor and it should update automatically.

i know i ask a lot of questions but some of these mod are a little confusing to get working :)

so i need a little help

cheers
Yes its really me :)

Derron

Please use the search - I am pretty sure this question was asked already some months ago.

keywords for you and google: interprocess communication, sockets, pipeline, ...


Search for the MaxIDE sources, it talks to the debugger/process when you debug your program.


bye
Ron

wadmixfm

yes ok

but can blitzmax ng have 2 instances running at the same time ??

Yes its really me :)

Derron

I do not understand. What instances? of bmk.exe, bcc.exe, maxide.exe, yourapplication.exe. .. ?

Why should it not allow it? simply execute your binary twice and it will run twice.


bye
Ron

Dabz

#4
I think they mean build and run the app twice as separate processes... But the IDE attaches itself to the process so when you click "Build and run", great, click "Build and run" again, BlitzMax closes the first one down and fire's a new process of the app back up.

I mean, they could run the app again from the first process, but they'll have to wangle it so they don't keep on calling it every time a new process of the app is create... Cos that'll be a fun result! :D

Or, they could create a script or something that builds and runs two processes from the same source, they have the source code for the IDE, so all they need to do is customize the IDE to fire this script up from, say, the Program menu, and viola.

But then, all debugging features or messages from their app in the Output tab will be lost if they use something external.

Either which way or whatever, what they want isnt a thing, but it can be, they just need to implement the system themselves to their needs really.

Dabz

Intel Core i5 6400 2.7GHz, NVIDIA GeForce GTX 1070 (8GB), 16Gig DDR4 RAM, 256GB SSD, 1TB HDD, Windows 10 64bit

wadmixfm

if i run my compiled program it opens but if i try to open it again with the one already open it reverts to the 1st one

so my question is can i open 2 blitzmax programs created with blitzmax ng so i can communicate with the first one to the second ??

lets say the first is the master

and the second is the slave

type my name on the first and press enter and it then sends it to the seconds program which will print it to the screen

lee
Yes its really me :)

wadmixfm

#6
i am trying to make a teleprompter so that the first one loads in the song and the data and then passes it to the second program and displays the song data only

lee

just letting you know i am running or trying to get this working on a mac with 2 monitors so i can send the second program to the 2nd monitor and just display the data on that monitor

thanks

Yes its really me :)

Midimaster

#7
didn't you ask this question in 2022?

https://www.syntaxbomb.com/....#msg347055637

Didn't you get it to work?

If you want to communicate between 2 apps, there are several ways to do it. Important would be how fast you need the communication.

The super easy way is to use a common folder with a common text file. There you write something with App-1. App-2 is watching the date/time of this file and when the timestamp changed it reads the file. This is slow!

This works via common.txt:

Save this code into your project folder. Then start the first EXE from the IDE (>>>red screen). Then open your project folder and start the app again (green screen). When closing the first app the second will close (crash) too!

Code (vb) Select
SuperStrict
Graphics 400, 300
Global WhoIsMaster:Int, time:Int, Message:Int

Global LastTime:Int, Received:String

If FileSize("common.txt")=-1
    SaveText "hello", "common.txt"
    WhoIsMaster=1
Else
   
EndIf
Repeat
    Cls
    If WhoIsMaster=1
        SetClsColor 111,0,0
        DrawText " I am master",100,100
        DrawText " Sending...Message=" + Message,100,130
        If time<MilliSecs()
            Message=Rand(10000,99999)
            time = MilliSecs()+3000
            SaveText "HELLO" + Message, "common.txt"
        EndIf
    Else
        SetClsColor 0,111,0
        DrawText " I am slave",100,100
        If LastTime<>FileTime("common.txt")
            lastTime = FileTime("common.txt")
            Received = LoadText("common.txt")
        EndIf    
        DrawText " file time= " +  LastTime, 100,130
        DrawText " Last Message= " +  Received, 100,160
    EndIf
    Flip 1
Until AppTerminate()
If WhoIsMaster=1
    DeleteFile "common.txt"
EndIf




I would suggest to read something about the GameNet module if you need it faster... or TSocket() where you can send Streams between  apps on different computers.
...back from North Pole.

Midimaster

#8
You always can start the app twice... but not from the IDE. And consider: You need to compile the app in RELEASE mode not in DEBUG mode!

how to start?
You need to open your project folder and start both (or the second) EXE from there. And consider: both will start on the same area of the screen. So... to see the first one, you have to move its window a little bit before starting the second EXE.
...back from North Pole.

Midimaster

Here is a GNET example. There are two apps SERVER and SLAVE. both need to be compiled in RELEASE mode.

At first start the SERVER:
SuperStrict
' gnetserver

AppTitle="GNet Server Example"
Graphics 640,480,0,80

Global Host:TGNetHost=CreateGNetHost()


If Host
   Print "Einen Server erstellt"
Else
   Print "Konnte Server nicht erstellen"
EndIf

Global player1:TGNetObject = CreateGNetObject(Host)

Local player_x:Int=0
Local player_y:Int=0

Const GNET_PLAYER_X:Int=0
Const GNET_PLAYER_Y:Int=1




Global erfolg:Int =GNetListen(Host,12345)

If erfolg
   Print "Server horcht nun auf den Port 12345"
Else
   Print "Konnte Socket nicht binden"
EndIf

While Not KeyDown(KEY_ESCAPE)
   Cls
   GNetSync(Host)
  
   'If (GNetAccept(Host))
   '   Print "Ein Client will sich verbinden"
     
     
   'End If
  
   player_x=MouseX()
   player_y=MouseY()
  
   SetGNetFloat player1,GNET_PLAYER_X,player_x
   SetGNetFloat player1,GNET_PLAYER_Y,player_y

   For Local obj:TGNetObject=EachIn GNetObjects( host,GNET_ALL )
      If obj=player1
         DrawText "Me",player_x,player_y
      Else
         DrawText "Him",GetGNetFloat(obj,GNET_PLAYER_X),GetGNetFloat(obj,GNET_PLAYER_Y)
      EndIf
   Next
  
   Flip
   'FlushMem()
Wend


CloseGNetHost(Host)
Print "Server runtergefahren"

Windows will warn you, that a game network is started. but this is OK...


Then start the SLAVE:

SuperStrict
' gnetclient

AppTitle="GNet Client Example"
Graphics 640,480,0,80

Global Host:TGNetHost=CreateGNetHost()

Global player2:TGNetObject=CreateGNetObject(Host)

Local player_x:Int=0
Local player_y:Int=0

Const GNET_PLAYER_X:Int=0
Const GNET_PLAYER_Y:Int=1



Global Client:Int = GNetConnect(Host,"127.0.0.1",12345)

While Not KeyDown(KEY_ESCAPE)
   Cls
   GNetSync(Host)

   player_x=MouseX()
   player_y=MouseY()

   SetGNetFloat player2,GNET_PLAYER_X,player_x
   SetGNetFloat player2,GNET_PLAYER_Y,player_y

   For Local obj:TGNetObject=EachIn GNetObjects( host,GNET_ALL )
      If obj=player2
         DrawText "Me",player_x,player_y
      Else
         DrawText "Him",GetGNetFloat(obj,GNET_PLAYER_X),GetGNetFloat(obj,GNET_PLAYER_Y)
      EndIf
   Next
  
   Flip
  ' FlushMem()
Wend

Now move the mouse on both windows. This also work on 2 different computers within your local home zone.

...back from North Pole.

wadmixfm

#10
deleted
Yes its really me :)

wadmixfm

Import MaxGui.Drivers

Global lyr$[40]

For Local i=0 To 39
lyr$[i]=String i
Next

Global window:TGadget = CreateWindow( "Lyric Window", 130, 20, 800, 700 )

Global textarea:TGadget = CreateTextArea( 0, 0, ClientWidth(window), ClientHeight(window), window )
Global MyGuiFont:TGuiFont = LookupGuiFont( GUIFONT_SYSTEM, 20,  0 )
SetGadgetFont textarea, MyGuiFont
SetGadgetLayout( textarea, EDGE_ALIGNED, EDGE_ALIGNED, EDGE_ALIGNED, EDGE_ALIGNED )
For Local i=0 To 39
SetGadgetTextColor( textarea, 255,255,255 )

SetGadgetText( textarea, lyr$[i])
ActivateGadget( textarea )
Next


While WaitEvent()

Select EventID()
Case EVENT_WINDOWCLOSE
End
Case EVENT_APPTERMINATE
End
End Select
Wend


ok how do i show all 39 numbers in the array in this maxgui window ???

lee
Yes its really me :)

Midimaster

your intention is not clear. When do you want to show this 39 lyrics? At the same time? In one textarea? Or 39 different text areas? Or one after the other?

Or are this 39 text lines of the same song?

Please send more informations
...back from North Pole.

wadmixfm

in the box that appears

like this

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
etc...

if i can get the array to print to the maxgui screen thats all i need

you see the singer is quite old and forgets the words sometimes and thats why i only need
40 lines to show the first 2 lines of each verse or chorus to remind him :)

cheers

lee
Yes its really me :)

wadmixfm

The code i posted above works but only shows the last number in the array

but i want it to show all the array upto 40 lines :)

but for the life of me i cannot get it too do

lee
Yes its really me :)