You need to hook into the engine's message loop for retrieving messages. The ScanMessage pointer can be used for that. It's a pointer in the ev struct that you can set to your own message interpreter function.

http://manual.conitec.net/prog_sending.html