Headless dedicated server with console that accepts input

Godot Version

4.2.1

Question

How do I setup my server so that it accepts input from the console that it was started from or starts it’s own console if ran from an executable? With the headless setup it doesn’t allow for input.

1 Like

I asked pretty much the same question and had no answer on it. I think you cannot achieve that by using default Godot’s tools so I suppose the only way to make it is write your own “console client” in something line C+ncurses or maybe some newer TUI frameworks for golang or python and make it communicate with your dedicated server by tcp socket.

You can use OS.read_string_from_stdin() to read the stdin. It’s a blocking function so you’ll need to use a Thread to process it. For example using it in an Autoload:

extends Node

var input_thread:Thread

func _enter_tree() -> void:
	input_thread = Thread.new()
	input_thread.start(_process_input)

func _exit_tree() -> void:
	input_thread.wait_to_finish()

func _process_input() -> void:
	var text = ""
	while text != "quit":
		printraw("Insert some text: ")
		text = OS.read_string_from_stdin().strip_edges()
		print("You inserted: %s" % text)
	get_tree().quit()
1 Like