in reply to websocket infinit loop

The infinite loop examples that I have found, are not suitable in this case because I need to use an infinite loop that can check for incoming data on both connections.

Look at the Mojo examples, the entire premise, is there is one loop, when an event happens, a subroutine is called ( a call back), the callback does the checking for things its concerned about ( one connection, another connection, something else )

All you do is "register" subroutines to respond to events, an event is anything, from connecting to a socket, to getting a message, to a timer expiring ...

Example Re^4: real-time output from Mojolicious WebSockets?

All these things can be part of the same program, as long as you're not blocking for long, it all just keep running
https://metacpan.org/pod/Mojolicious::Guides::Cookbook#Non-blocking
https://metacpan.org/pod/Mojolicious::Guides::Cookbook#WebSockets
https://metacpan.org/pod/Mojolicious::Guides::Cookbook#Synchronizing-non-blocking-operations