So I actually got this to work immediately after writing this out, but I'll put this here just in case it helps someone. The code was executing too quickly and the port-forward wasn't ready, so just adding Thread.sleep(2000) was enough to fix it.
Thread.sleep(2000)