Home  Search  Register  Login  Recent Posts

Information on DTN's Industries:
DTN Oil & Gas | DTN Trading | DTN Agriculture | DTN Weather
Follow DTNMarkets on Twitter
DTN.IQ/IQFeed on Twitter
DTN News and Analysis on Twitter
»Forums Index »Archive (2017 and earlier) »IQFeed Developer Support »Connection Refused error
Author Topic: Connection Refused error (7 messages, Page 1 of 1)

jonnyb
-DTN Evangelist-
Posts: 122
Joined: Aug 15, 2012


Posted: Apr 29, 2022 09:46 AM          Msg. 1 of 7
Hello,

After using the same code to connect for many years, I'm suddenly having an issue with connecting to the socket admin port (connection refused socket exception). I can resolve the issue by pausing the thread for a few seconds, but I'm curious why this is now necessary. Appreciate any input on what might have changed. Here's the code below with some notes on what's different:

 
Process process = new ProcessBuilder("iqconnect.exe", "my login stuff").start();

ThreadUtils.pause(5000); //<-------------------------------THIS WAS NOT NECESSARY IN THE PAST

System.out.println("Verifying if IQConnect is connected to the server");

// verify everything is ready to send commands.
boolean bConnected = false;

// connect to the admin port (9300).
Socket sockAdmin = new Socket(InetAddress.getByName("localhost"), 9300);//<---------------------------CONNECTION REFUSED ERROR THROWN AT THIS LINE

BufferedReader bufreadAdmin = new BufferedReader(new InputStreamReader(sockAdmin.getInputStream()));
BufferedWriter bufwriteAdmin = new BufferedWriter(new OutputStreamWriter(sockAdmin.getOutputStream()));
String strAdminLine = "";

// loop while we are still connected to the admin port or until we are connected
while (((strAdminLine = bufreadAdmin.readLine()) != null) && !bConnected)
{
System.out.println(strAdminLine);

if (strAdminLine.indexOf(",Connected,") > -1)
{
System.out.println("IQConnect is connected to the server.");
bConnected = true;
}
else if (strAdminLine.indexOf(",Not Connected,") > -1)
{
System.out.println("IQConnect is Not Connected.\r\nSending connect command.");
bufwriteAdmin.write("S,CONNECT\r\n");
bufwriteAdmin.flush();
}
}


DTN_Gary_Stephen
-DTN Guru-
Posts: 401
Joined: Jul 3, 2019


Posted: Apr 29, 2022 10:46 AM          Msg. 2 of 7
Nothing has changed on our end. IQFeed wouldn't block you from connecting to the Admin socket. I suspect something external is using port 9300, or otherwise interfering with traffic to it. You can find this in Command Prompt. Send this command:

netstat -ano | findStr “9300”


This will turn up one or more lines like this:


C:\Users\Gary.Stephen>netstat -ano | findStr "9300"
TCP 127.0.0.1:9300 0.0.0.0:0 LISTENING 17736
TCP 127.0.0.1:9300 127.0.0.1:59229 ESTABLISHED 17736
TCP 127.0.0.1:59229 127.0.0.1:9300 ESTABLISHED 21048


The number on the far right is the process ID. To find what each one represents, enter this on the command line. (The actual numbers will vary. Change the number, and repeat the command once for each number, as appropriate.)

tasklist /fi "pid eq 17736"


And this will tell you exactly what’s using the port:

Image Name PID Session Name Session# Mem Usage

========================= ======== ================ =========== ============
iqconnect.exe 17736 Console 1 17,112 K


iqconnect.exe is what you want to be using to be port 9300, but see if this discovers that some rogue app is using it. You can then decide what to do: reconfigure it or IQFeed to use something else (see below), or just disable the conflicting app.

Other comments:

  • A Logitech app called lghubupdater commonly interferes with port 9100 in this way. Most people just disable that app to resolve the conflict.

  • It is possible to customize what port numbers IQFeed uses, by making registry changes in Computer\HKEY_CURRENT_USER\Software\DTN\IQFeed\Startup. I recommend caution when doing this, though, because third-party software (and third-party code bases) don't always implement this.

  • Make sure you have whitelisted the entire IP range IQFeed uses, which is: 12.36.218.128 – 12.36.218.254 (CIDR: 12.36.218.128/25), Ports: 60000-60060. I don't think that's the issue here, but it's always good to make sure of this.


I hope this helps! Beyond that, I'd need to get more information from you. You can send me a support email or chat, and I will investigate further.

Sincerely,
Gary Stephen
DTN IQFeed Implementation Support Specialist

jonnyb
-DTN Evangelist-
Posts: 122
Joined: Aug 15, 2012


Posted: Apr 29, 2022 02:38 PM          Msg. 3 of 7
Thank you, Gary! I will work through this on Monday. The odd thing for me is that pausing the thread for a few seconds makes the issue go away...I'll have to be nimble with my command prompts.

jonnyb
-DTN Evangelist-
Posts: 122
Joined: Aug 15, 2012


Posted: May 2, 2022 08:28 AM          Msg. 4 of 7
Good morning, Gary.

I've had a chance to play around with this little and nothing gets returned for the netstat call on 9300. Given that and the fact that the issue goes away if I delay a few seconds after starting iqconnect.exe, it seems that the connection is getting refused because there's nothing at 9300 yet (until iqconnect.exe fully loads).

Can that be what's going on? If so, it's very odd that a timing issue would suddenly arise after years of running the same code. Also, the DTN samples are written without a thread delay, so seems unlikely that this behavior would be possible.

Anyhow, I do have a workaround, but I'd really like to understand the behavior of what's happening, if possible. Appreciate any further input.
Edited by jonnyb on May 2, 2022 at 08:30 AM

DTN_Gary_Stephen
-DTN Guru-
Posts: 401
Joined: Jul 3, 2019


Posted: May 4, 2022 11:30 AM          Msg. 5 of 7
Can you provide a iqconnect.txt log file, with all logging turned on? You can send it to me at the developer support address. A "Test" on the IQConnect tab of the Diagnostics app would be helpful also.

Sincerely,
Gary Stephen
DTN IQFeed Implementation Support Specialist

jonnyb
-DTN Evangelist-
Posts: 122
Joined: Aug 15, 2012


Posted: May 6, 2022 01:54 PM          Msg. 6 of 7
I inserted this after the ProcessBuilder line and it seems to do the job. Perhaps, it's a slight improvement over simply pausing the thread. Maybe it'll help someone else in the future. Anyway, thanks for offering to look into to it further but not sure it's worthwhile investing more time (of course, that assumes the problem doesn't come back). Thanks again.

 
Socket sockAdmin = null;
int retryCounter = 0, threshold = 15;

while (retryCounter < threshold && sockAdmin == null)
{
try
{
retryCounter++;

// connect to the admin port (9300).
sockAdmin = new Socket(InetAddress.getByName("localhost"), 9300);
}
catch (ConnectException e)//host and port combination not valid
{
e.printStackTrace();

ThreadUtils.pause(2500);
}
}

DTN_Gary_Stephen
-DTN Guru-
Posts: 401
Joined: Jul 3, 2019


Posted: May 10, 2022 08:22 AM          Msg. 7 of 7
I'm glad you were able to work around the problem! Thanks for letting me know.

Sincerely,
Gary Stephen
DTN IQFeed Implementation Support Specialist
 

 

Time: Mon July 15, 2024 3:34 PM CFBB v1.2.0 9 ms.
© AderSoftware 2002-2003