I was getting this error for the last few days
When I would initiate the chat from mirc it would fail for: invalid port
when I would /ctcp botnick chat it would connect fine
the problem was mirc settings. DCC PASSIVE was ON
/dcc passive off
*fixed*