Inter-process communication

BlitzMax Forums/BlitzMax Beginners Area/Inter-process communication

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

You can send update values to the client(s).

master.bmx
SuperStrict

Framework pub.freeprocess

Import brl.eventqueue
Import maxgui.drivers
Import brl.timer

Local Wnd_Main:TGadget = CreateWindow("Host", 100, 100, 300, 250, Null, WINDOW_TITLEBAR | WINDOW_STATUS) 

Local Btn_Start:TGadget = CreateButton("Start", 20, 20, 70, 30, Wnd_Main) 
Local Btn_Stop:TGadget = CreateButton("Stop", 20, 60, 70, 30, Wnd_Main) 
	DisableGadget Btn_Stop
	
Local Btn_Send:TGadget = CreateButton("Send", 20, 100, 70, 30, Wnd_Main) 
	DisableGadget Btn_Send
	
Local Txf_SendMessage:TGadget = CreateTextField(20, 140, 200, 20, Wnd_Main) 

Local proc:TProcess, Listen:Int = 0, procmsg:String

CreateTimer 60
Repeat
	Select WaitEvent() 
		Case EVENT_TIMERTICK
			If Listen = 1
				If proc.Status() And proc.pipe.ReadAvail() 
				
				 procmsg = proc.pipe.ReadLine().Replace(Chr(13), "").Replace(Chr(0), "") 
					
					If procmsg
					   SetStatusText Wnd_Main, CurrentTime() + "[" + procmsg + "]"
						
						If procmsg = "EXIT"
							Print "Terminate..."
							
							proc.Terminate() 
							proc = Null
						   End
						End If
						
					End If
					
				End If
				
			   proc.pipe.WriteLine("~~") 
			   
			End If
			
		Case EVENT_GADGETACTION
			Select EventSource() 
			
				Case Btn_Send
				 If proc Then proc.pipe.WriteLine(TextFieldText(Txf_SendMessage)) 
					
				Case Btn_Start
				  proc = CreateProcess("proc.exe") 
					DisableGadget Btn_Start
					EnableGadget Btn_Stop
					EnableGadget Btn_Send
					SetStatusText Wnd_Main, "Process Started"
					
				   Listen = 1
				
				Case Btn_Stop
					DisableGadget Btn_Send
					DisableGadget Btn_Stop
					EnableGadget Btn_Start
					SetStatusText Wnd_Main, "Process Stopped"
					
					Listen = 0
					proc.Terminate() 
					proc = Null
					
			End Select
			
		Case EVENT_WINDOWCLOSE
			End
			
	End Select
	
Forever
End


proc.bmx
SuperStrict

Framework brl.standardio

Import brl.eventqueue
Import maxgui.drivers
import brl.timer

Local Wnd_Main:TGadget = CreateWindow("Client", 400, 100, 300, 250, Null, WINDOW_TITLEBAR | WINDOW_STATUS) 

Local Btn_Stop:TGadget = CreateButton("Stop", 20, 20, 70, 30, Wnd_Main) 
Local Btn_Send:TGadget = CreateButton("Send", 20, 60, 70, 30, Wnd_Main) 

Local Txf_SendMessage:TGadget = CreateTextField(20, 140, 200, 20, Wnd_Main)  

CreateTimer 60
Repeat
	Select WaitEvent() 
		Case EVENT_TIMERTICK
		  Local stdmsg:String = StandardIOStream.ReadLine() 'ReadStdin() 
			
			If stdmsg
				If stdmsg <> "~~"
					SetStatusText Wnd_Main, CurrentTime() + "[" + stdmsg + "]"
					
					'Print "RECEIVED"
				EndIf
				
				If stdmsg = "EXIT"
					Print "EXIT"
					
				   Exit
				End If
				
			End If
			
		Case EVENT_GADGETACTION
			Select EventSource() 
				Case Btn_Send
					Print TextFieldText(Txf_SendMessage) 
					
				Case Btn_Stop
					Print "EXIT"	
				
			End Select
			
		Case EVENT_WINDOWCLOSE
			Print "EXIT"
		   End
			
	End Select
	
Forever
End