Added functionality for setPort(0). Code copied from #124