Reworked error handling in ports and socket ports.