def parse_port_id (parameters, port_id = "portno"):
    """
    Parse command parameters to get the socket port ID for the command.
    
    :param parameters: The list of parameters provided to the command.
    :param port_id: The name of the port ID parameter.
    
    :return The socket port ID to use for the command.  The port ID provided by the request will be
    made negative if the ID is not valid.  A 0 is returned when no port ID is provided.
    """
    
    try:
        port = int (parameters.get (port_id, 0))
        if (port > 4):
            port = -port
            
    except:
        # If there is an exception getting the parameter, assume no valid parameter is available.
        port = 0
        
    return port