pub.freeprocess help

BlitzMax Forums/BlitzMax Programming/pub.freeprocess help

wmaass(Posted 2009) [#1]
I was looking for a way to make my BlitzMax apps talk to each other and found pub.freeprocess. For the most part it works for me but I've run into an issue that is holding me up. Basically I have a simple app that sends a message to a MiniB3D app. All is fine except that the MiniB3D app halts when reading the message. Here is the main loop of the MiniB3D app:


While Not KeyHit(KEY_ESCAPE)

	TurnEntity world,0,1,0

	
	RenderWorld
	
	'begin 2D stuff
	TGlobal.BeginMax2D
		DrawText myevent,0,0
	TGlobal.EndMax2D
	'end of the 2d stuff
	
	Flip
	
	Select WaitEvent()
		Case EVENT_TIMERTICK
			stdmsg = StandardIOStream.ReadLine() 'ReadStdin()
			If stdmsg
				If stdmsg <> "~~"
					myevent = stdmsg 
				EndIf
			EndIf
		Default
	End Select

Wend
End



If I comment out
stdmsg = StandardIOStream.ReadLine() 'ReadStdin()


the program runs ok. Anyway to read the message from the other app without coming to a halt?


plash(Posted 2009) [#2]
One (ugly) solution is to have the other program send a 'sync' character on a very small timer.
Preferably any non-common or non-renderable character.

Another route might be threading the communications.
Or, more simply, there might just be a way to check if the stream actually has any data in it at all (ReadAvail for sockets/etc), then you can read it in..
Not sure if that has been tried before or if it's possible (though it probably is possible).


wmaass(Posted 2009) [#3]
Hmm, I think I'll take a look at threading it. Thanks for the tip Plash.


wmaass(Posted 2009) [#4]
Well I got the threading to work somewhat, then I came upon a post (forgot where now) that was using sockets, banks and streams that seems to work great for me. So I have a question about good practice.

I have a function that sends data to the server when a key is pressed like so:

Local bank:TBank = New TBank
Local data:TBankStream = CreateBankStream(bank)
Local name:String = "Player"	
	
data.WriteInt(name.length)
data.WriteString(name)
data.WriteInt(x1)
data.WriteInt(y1)
server.send(BankBuf(bank), StreamSize(data))


...which works but is this good? Seems to me that I should clear out the bank and tbankstream after the server.send.

EDIT - I found CloseStream() but I have yet to find the BMax version of FreeBank.


plash(Posted 2009) [#5]
...which works but is this good? Seems to me that I should clear out the bank and tbankstream after the server.send.
You should be closing the bank stream, but I think you can leave the actual bank alone. The send might be delayed (or not), anyhow, I'm not sure if it makes a copy of the data or not so as long as it references the bank buffer, it wont be deleted. So you should just leave the bank alone.


wmaass(Posted 2009) [#6]
Ok, just checking. My concern was that I was gobbling up memory each time the bank was created. Thanks Plash.