ZeroMQ addon for Godot 4.2.2 - 4.4
use godot_zeromq_bin. see instruction
@onready var zmq_receiver = ZMQReceiver.new_from("tcp://localhost:5555", ZMQ.SocketType.PULL, ZMQ.ConnectionMode.CONNECT, "")
@onready var zmq_sender = ZMQSender.new_from("tcp://localhost:5555", ZMQ.SocketType.PUSH, ZMQ.ConnectionMode.BIND, "", false)
func _ready():
add_child(zmq_receiver)
add_child(zmq_sender)
zmq_receiver.onMessageString(func(str: String):
print("[ZMQ Receiver] Received: ", str)
)
while true:
await get_tree().create_timer(1.0).timeout
print("[ZMQ Sender] Sending: ", "Hello World")
zmq_sender.sendString("Hello World")
func _exit_tree():
zmq_receiver.stop()
zmq_sender.stop()
remove_child(zmq_receiver)
remove_child(zmq_sender)more example, see GDScript of demo project
new_from(address: String, socket_type: int, connection_mode: int, socket_filter: String) -> ZMQReceiveronMessageString(callback: Callable[[String], void])onMessageBytes(callback: Callable[[PackedByteArray], void])sendString(message: String) -> voidsendBytes(message: PackedByteArray) -> voidstop() -> void
new_from(address: String, socket_type: int, connection_mode: int, socket_filter: String, auto_receive_on_sender: bool) -> ZMQSenderonMessageString(callback: Callable[[String], void])(ONLY enabled to use when auto_receive_on_sender is true, orbeginReceiveRequest()called)onMessageBytes(callback: Callable[[PackedByteArray], void])(ONLY enabled to use when auto_receive_on_sender is true, orbeginReceiveRequest()called)sendString(message: String) -> voidsendBytes(message: PackedByteArray) -> voidbeginReceiveRequest() -> void(ONLY enabled to use when auto_receive_on_sender is false)stop() -> void
socket_filteris ONLY used whensocket_typeisSUBonMessageStringandonMessageBytesare exclusive, you can ONLY use one of them
enum SocketType {
PUB = 1,
SUB = 2,
REQ = 3,
REP = 4,
DEALER = 5,
ROUTER = 6,
PULL = 7,
PUSH = 8,
XPUB = 9,
XSUB = 10,
STREAM = 11
}
enum ConnectionMode {
BIND = 1,
CONNECT = 2
}- SUB/PUB, PUSH/PULL, REQ/REP (tested)
- untested but enabled: DEALER/ROUTER, PAIR/PAIR, XPUB/XSUB, STREAM
see project/ directory
(This process is needed only if you build this plugin by your own)
- NOTE: before scons, you need to install cppzmq and ZeroMQ.
- on Ubuntu/Mac:
brew install cppzmq(installed dependency will auto detected from/home/linuxbrew/.linuxbrew/, and you can also use vcpkg if you want, path should be~/vcpkg/) - on Windows:
./vcpkg install cppzmq(installed dependency will auto detected fromC:/vcpkg/)
- on Ubuntu/Mac:
$ git submodule update --init --recursive --recommend-shallow --depth 1
$ scons
$ scons target=template_release
$ godot project/project.godot # (only first time)
$ godot --path project/ # run demo- godot_zeromq: MIT License
- cppzmq: MIT License
- libzmq: Mozilla Public License 2.0 (please also check https://zeromq.org/license/)