1

When running the code to connect to Gmail provided by TLama on How to login to a Gmail account and get number of messages in a mailbox with TIdIMAP4? it works wonderfully well in Delphi 5 and Delphi 2007.

I try the same code on Delphi XE3, but strange enough I got 'Socket Error #10061 Connection refused' error when in the IDE or when I launch the exe generated in the \win32\debug directory directly from the file explorer. If I launch the .exe generated in the \Win32\release directory it works correctly!

I tried to put the ssleay32.dll and libeay32.dll in all sort of directories but it still doesn't work and I'm not sure it's related to that.

Indy on Delphi XE3 is version 10.5.9.0. (what originally shipped with my Delphi XE3 Update 1).

Any help greatly appreciated!

Community
  • 1
  • 1
Hugues M
  • 13
  • 3

1 Answers1

0

Socket error 10061 means one of two things:

  1. you tried to connect to an IP/Port that is not listening for connections at all.

  2. you tried to connect to an IP/Port that is listening for connections, but does not have any available slots to accept new client connections at that particular moment.

There is no way to differentiate between the two possibilities on the client side.

There should be no difference in how Indy manages its sockets in Debug vs Release builds. The issue you are seeing has nothing to do with the DLLs, since they are not invoked until after the underlying socket connection is established first (however, you can use Indy's IdOpenSSLSetLibPath() function in the IdSSLOpenSSLHeaders unit to tell Indy where the DLLs are located, if needed).

Double-check the Port property when calling Connect(). Setting the UseTLS property can actually change the Port value. If you need to set both properties, set UseTLS first, then set Port if you need to use a different value then what Indy assigned.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • I tried modifying the port after the UseTLS, but still the same error. If I check the port just before connecting in debug mode I correctly have 993. – Hugues M Jan 04 '13 at 21:52
  • Just to be sure, I tried using IdOpenSSLSetLibPath() to explicitly mention the DLL but as you expected it still doesn't work. It's very strange. I retried launching the .exe in the win32\release\ directory and this version works. – Hugues M Jan 04 '13 at 22:01
  • Since its the debug version that fails, and while you are inside the IDE, havee you tried simply stepping through the Indy source code to make sure everything is being set up properly? Using the latest Indy 10 SVN snapshot, I have no problem connecting to Gmail IMAP while running in Debug mode. So it has to be something in your setup. – Remy Lebeau Jan 04 '13 at 22:48
  • I installed Indy 10.5.9.4885 but still have the same problem. I stepped through and in TIdSocketHandle.Connect it calls GStack.Connect(Handle, PeerIP, PeerPort, FIPVersion) with params (416,173.194.78.108, 993, Id_IPv4). It goes in error when it calls Stub_connect in IdWinsock2 where the result is -1. – Hugues M Jan 05 '13 at 09:27
  • That means that Indy is working properly. Your OS is simply not able to connect to 173.194.78.108:993, that's all. Like I said, it works fine for me, but my PC resolves imap.gmail.com to 173.194.79.108 instead, so either your PC's DNS is not configured correctly, or something on your network is blocking the connection, or more likely Gmail is load-balancing or the like and 173.194.78.108 is just not working correctly on Gmail's end but 173.194.79.108 is. – Remy Lebeau Jan 05 '13 at 18:42
  • Thanks for still giving me tips Remy. Unfortunately I'm still stuck. I tried to connect to imap.gmail.com:993 in Outlook. No problem. I can also connect with the exe build with exactly the same source on Delphi2007 and Delphi 5. I disabled the Comodo Internet security and the Windows firewall is disabled. I reinstalled latest version of Indy. Now all exe's build by Delphi XE3 give me the same error. Maybe I have to reinstall Delphi XE3... – Hugues M Jan 06 '13 at 09:42
  • I assure you, there is NO difference in how `GStack.Connect()` works in Release vs Debug mode. It is just a wrapper around the Winsock `connect()` function. The `-1` and `10061` values are coming from Winsock itself, so this is an OS issue, not an Indy issue. If you use the `OnStatus` event, the `hsConnecting` state tells you the exact IP that is being connected to. Make sure both Release and Debug builds are attempting to connect to the same IP. – Remy Lebeau Jan 06 '13 at 09:57
  • Remy, the problem is solved. Apparently even when I thought my Comodo firewall was disabled it was still running. After checking all the logs I realised this was the culprit. Thank you so much for your patience and tips as this brought me in the right direction. – Hugues M Jan 06 '13 at 10:27