pub.freeprocess help
BlitzMax Forums/BlitzMax Programming/pub.freeprocess help
| ||
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? |
| ||
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). |
| ||
Hmm, I think I'll take a look at threading it. Thanks for the tip Plash. |
| ||
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. |
| ||
...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. |
| ||
Ok, just checking. My concern was that I was gobbling up memory each time the bank was created. Thanks Plash. |