added length
updated to use localPort
removed constants to common and added new error check