Finally got server to work by removing loop in onConnect.