is it necessary to connect your encoding device and wowza streaming engine device to the same wifi network?

I have wowza streaming engine setup on another device and encoding from a different device which is connected to different wifi network. When I try to secure a connection using rtmp it gives me the following error.

"Failed to connect to the server. The connection timed out. Make sure you’ve configured a valid streaming service and no firewall is blocking the connection.

I have tried encoding on the same device which has the wowza streaming engine running and I was able to secure the connection seamlessly with no problems whatsoever. I don’t understand what is the problem here?

What’s the device you’re using to encode from where you get the error? We would need that information. What ports do you have configured?