Two blitz apps communicating

Blitz3D Forums/Blitz3D Programming/Two blitz apps communicating

Jasu(Posted 2006) [#1]
Is there an efficient way for two separate Blitz programs to communicate?

I wan't my game to have two separate threads, a client and a server sending data packets back and forth. In connections through WAN I would use TCP or UDP, but when playing the game on single machine, using network to communicate is strange. I wouldn't want to use that if I don't really need to.

Blitz functions that haven't catched my eye? Windows API functions?

Of course if blitz3d supports multithreading, that would be solution, but I haven't found any info on that.


Picklesworth(Posted 2006) [#2]
The Windows window message WM_COPYDATA is built specifically for that... you may need to write a DLL for it to work happily, though. It is in User32, sent by SendMessage in the Windows API.


Matty(Posted 2006) [#3]
I used UDP to send commands between two editors for a game I was making on the same machine (one written in blitzplus other written in blitz3d) with no problems. What is the reason you wish to not use networking commands?


Jasu(Posted 2006) [#4]
User could have the whole network service disabled, but this is of course a rare case.

Using user32 sounds good, but a bit complicated. I wonder how fast it is compared to having both stuff in one exe? Writing DLL's is new to me and I have no tools make them. If this gets too difficult, I'll probably use UDP first and implement WM_COPYDATA later if needed. Or?


jfk EO-11110(Posted 2006) [#5]
Imlementing UDP properly may take as much time as doing the WM_COPYDATA thing. It is very useful because you'll learn how to use Windoes Api functions using Blitz userlib declarations.

I don't know exactly about WM_COPYDATA, but usually you only need to write a DLL because Blitz doesn't support Pointers. But with a little hack this can be solved nevertheless:

In the "userlibs" folder needs to be a file named "kernel32.decls" containing at least the following lines:
api_RtlMoveMemory(Destination*,Source,Length) : "RtlMoveMemory"


In the Blitz App you'll then be able to find out the physical adress of a bank this sway:
mybank=createbank(256)
pointer =AddressOf(mybank)
...
Function AddressOf(Bank) ; Find the correct Adress of a Bank (for C *Pointer)
Local Address = CreateBank(4) 
api_RtlMoveMemory(Address,Bank+4,4) 
Return PeekInt(Address,0) 
End Function


Im pretty sure this WM_COPYDATA function requires such a pointer to write the Data to. An other reason why it could fail is Memory protection.

Well, not sure of this, tho I managed to use a lot of Api calls directly from within blitz where other coders used to write DLLs for.