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 »Problem closing down and the restart
Author Topic: Problem closing down and the restart (3 messages, Page 1 of 1)

fng
-Interested User-
Posts: 31
Joined: Aug 2, 2007


Posted: Jun 28, 2010 08:51 AM          Msg. 1 of 3
I am running a program where I use some of the code you have in your demo program.

I have the program to close down and restart if I do not get any data in 30 sec.

When the close happens this is the code that is executed correctly:

Private Sub Level1Socket_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Try
RemoveClientApp(Me.Handle.ToInt32)
FileLog("DTNIQ Close Event - Correct Close Down!")
Catch ex As Exception
FileLog("CATCH Error in DTNIQ Close Down! " & ex.Message)
End Try
End Sub
According to my log this works fine.

BUT - sometimes when I try to restart the program I get this error from the Onconnect sub:

"No connection could be made because the target machine actively refused it 127.0.0.1:5009"

THIS IS the ONCONNECT SUB:

Public Sub OnConnect()
Try
m_sockIQConnect = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
Dim ipLocalhost As IPAddress = IPAddress.Parse("127.0.0.1")
Dim iPort As Integer = GetLevel1Port()
Dim ipendLocalhost As Net.IPEndPoint = New IPEndPoint(ipLocalhost, iPort)
m_sockIQConnect.Connect(ipendLocalhost)

WaitForData()
'If everything OK then start Timer
'----------------------------------------------------------------
btnWatch.Enabled = True
btnWatch.PerformClick()
FileLog("Onconnect OK - Watch and Timer Start")
Timer1.Start()
'--------------------------------------------------------------
Catch ex As Exception
FileLog("Error from OnConnect: " & ex.Message)
Me.Close()
End Try
End Sub

To me it looks like the RemoveClientApp sometimes does not close the connection, any suggestions please!
Catch ex As Exception
FileLog("CATCH Error in DTNIQ Close Down! " & ex.Message)
End Try
End Sub
According to my log this works fine.

BUT - sometimes when I try to restart the program I get this error from the Onconnect sub:

"No connection could be made because the target machine actively refused it 127.0.0.1:5009"

THIS IS the ONCONNECT SUB:

Public Sub OnConnect()
Try
m_sockIQConnect = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
Dim ipLocalhost As IPAddress = IPAddress.Parse("127.0.0.1")
Dim iPort As Integer = GetLevel1Port()
Dim ipendLocalhost As Net.IPEndPoint = New IPEndPoint(ipLocalhost, iPort)
m_sockIQConnect.Connect(ipendLocalhost)

WaitForData()
'If everything OK then start Timer
'----------------------------------------------------------------
btnWatch.Enabled = True
btnWatch.PerformClick()
FileLog("Onconnect OK - Watch and Timer Start")

Example from My LOG:
8:55:49 AM DTNIQ Close Event - Correct Close Down!
8:57:18 AM Error from OnConnect: No connection could be made because the target machine actively refused it 127.0.0.1:5009
8:57:18 AM DTNIQ Close Event - Correct Close Down!
8:57:33 AM Error from OnConnect: No connection could be made because the target machine actively refused it 127.0.0.1:5009

FNG

DTN_Steve_S
-DTN Guru-
Posts: 2096
Joined: Nov 21, 2005


Posted: Jun 28, 2010 10:39 AM          Msg. 2 of 3
FNG, the RemoveClientApp call doesn't actually shut down the feed. The only way to close the app is to either right-click the notification area icon and choose "Exit" from the menu or to disconnect all level 1 connections. IQConnect should exit automatically once there are no longer any connections to the level 1 port.

Also, I don't see anything in your code that actually launches the feed. If your app shuts down and IQConnect closes (as expected), then when you relaunch your app, there is nothing to connect to since IQConnect is no longer running which would cause the error message you are getting.

fng
-Interested User-
Posts: 31
Joined: Aug 2, 2007


Posted: Jun 28, 2010 12:34 PM          Msg. 3 of 3
Hi -thanks for your answer.
When the program loads it connect to DTN - Part of the code:

Dim sRes As Short = 1

'Dim dtn_port As Integer

Try

sRes = RegisterClientApp(Me.Handle.ToInt32, strProdID, strProdKey, strProdVersion)
If sRes <> 0 Then
FileLog("NO LogON - Close")
Me.Close() ' Restart from scheduler
End If

' ************************************* INIT Files *******************************************



'********************************************* Start Connection og Watch *********************************************************
dtn_port = GetLevel1Port()
OnConnect()

Catch ex As Exception
FileLog("Error Load IQConnect " & dtn_port)
Me.Close()
End Try
End Sub

I think it must have something to do with a thread which is still running when I try to close the program down. Does that sound correct?

Flemming
 

 

Time: Mon June 30, 2025 4:17 PM CFBB v1.2.0 17 ms.
© AderSoftware 2002-2003