Your code is incomplete, and there are many variables undeclared, so I imagine they are global variables. I have tried to make it work and I have replaced MensajeError() with GetErrorMessage().
The error message got is:
No se puede establecer una conexión ya que el equipo de destino denegó expresamente dicha conexión.
The error is the WSAECONNREFUSED (10061). There is an explanation here, and the reason usually is that your trying to connect to an address and a port where nobody is listening.