News:

  • June 09, 2026, 07:32:43 AM

Login with username, password and session length

Author Topic: Problem closing open port  (Read 19326 times)

marc.turcotte

  • Jr. Member
  • **
  • Posts: 13
Problem closing open port
« on: June 12, 2009, 09:19:00 AM »
I think i have a problem closing the ports in my program... I came in this morning after letting my program run for 12 hours...
Was getting error 2407 or something querying the network. NetEdit 3 didnt want to scan the network neither... (Winsocket 10055 error)

I opened TCPView... and there was like an infinite number of lines like these:

Code: [Select]
VB6.EXE:3844 UDP mmturcot:1274 *:*
VB6.EXE:3844 UDP mmturcot:3259 *:*
VB6.EXE:3844 UDP mmturcot:4802 *:*
VB6.EXE:3844 UDP mmturcot:4899 *:*
VB6.EXE:3844 UDP mmturcot:4077 *:*
VB6.EXE:3844 UDP mmturcot:4519 *:*
VB6.EXE:3844 UDP mmturcot:2534 *:*
VB6.EXE:3844 UDP mmturcot:2317 *:*
VB6.EXE:3844 UDP mmturcot:1968 *:*

So i guess i maxed out the number of open sockets on my computer..?!

Read the following.. :

First part queries the whole network.

Code: [Select]
    ' if the network interface has already been opened, close it
    '
    If NetworkOK = True Then
        Rc = PASCAL_HEICloseTransport(TP)
        Rc = PASCAL_HEIClose()
    End If

    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ' Initialize the Ethernet Driver
    '
    DisplayText.Text = DisplayText.Text & vbCrLf & "[" + MyTime + "]  " + "Initializing IP transfer protocol..."
    Rc = PASCAL_HEIOpen(HEIAPIVersion)
    If Rc <> 0 Then
        DisplayText.Text = DisplayText.Text & vbCrLf & ""
        DisplayText.Text = DisplayText.Text & vbCrLf & "[" + MyTime() + "]  " + "Error " + Hex(Rc) + " trying to initialize the Ethernet driver"
        DisplayText.Text = DisplayText.Text & vbCrLf & ""
        DisplayText.Refresh
        DisplayText.SelStart = Len(DisplayText.Text)
        Reading_PLC_Error = 1
    Else
        '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        ' Initiaizize the Winsock protocol transport
        '
        TP.Transport = HEIT_WINSOCK
       
        '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        ' Using only IP PROTOCOL
       
        'If UseIP = True Then
        TP.Protocol = HEIP_IP
        'Else
        '    TP.Protocol = HEIP_IPX
        'End If
       
        Rc = PASCAL_HEIOpenTransport(TP, HEIAPIVersion, 0)
        If Rc <> 0 Then
            DisplayText.Text = DisplayText.Text & vbCrLf & ""
            DisplayText.Text = DisplayText.Text & vbCrLf & "[" + MyTime + "]  " + "Error " + Hex(Rc) + " trying to initialize the Winsock transport"
            DisplayText.Text = DisplayText.Text & vbCrLf & ""
            DisplayText.Refresh
            DisplayText.SelStart = Len(DisplayText.Text)
            Reading_PLC_Error = 1
        Else
            ' Using only IP PROTOCOL
            'If UseIP = True Then
            Pause 1 / 2
            DisplayText.Text = DisplayText.Text & "..........INITIALIZATION COMPLETED."
            DisplayText.Text = DisplayText.Text & vbCrLf & ""
            DisplayText.Refresh
            DisplayText.SelStart = Len(DisplayText.Text)
            'Else
            '    DisplayText.Text = DisplayText.Text & vbCrLf &"Initialized Ok, using IPX protocol"
            'End If
           
            NetworkOK = True
            'ScanNetwork.Enabled = True
            'If Connect.Enabled = True Then Connect.Enabled = False
                       
            'End If
        End If
   
        ' Scanning the network
        '
        'DisplayList.Clear
        DeviceCount = MAXDEVICES
   
        ' Do the Query
        '
        Rc = PASCAL_HEIQueryDevices(TP, aDevices(0), DeviceCount, HEIAPIVersion)
        If Rc <> 0 Then
            DisplayText.Text = DisplayText.Text & vbCrLf & "[" + MyTime + "]  " + "ERROR " + Hex(Rc) + " trying to query network"
            DisplayText.Text = DisplayText.Text & vbCrLf & ""
            DisplayText.Refresh
            DisplayText.SelStart = Len(DisplayText.Text)
            DeviceCount = 0

            Reading_PLC_Error = 1
        Else
            ' If the PASCAL_HEIQuery call was successful, DeviceCount will contain the
            ' number of Host Ethernet Devices on the network
            '
            DisplayText.Text = DisplayText.Text & vbCrLf & "[" + MyTime + "]  " + "Found" + Str(DeviceCount) + " devices on the Network..."
            DisplayText.Text = DisplayText.Text & vbCrLf & ""
            DisplayText.Refresh
            DisplayText.SelStart = Len(DisplayText.Text)
           
            If DeviceCount > 0 Then
               
                OnlineDevicesText.Text = DeviceCount
                OnlineDevicesText.Refresh
                DisplayText.Text = DisplayText.Text & vbCrLf & "[" + MyTime + "]  " + "  #      Device     MAC Address             IP Address              ID"
                DisplayText.Refresh
                DisplayText.SelStart = Len(DisplayText.Text)
   
                ' Error Flags
                '
                Dim DDError As Boolean, IPError As Boolean, IDError As Boolean
                DDError = False
                IPError = False
                IDError = False
               
                DetailLine = ""
               

                    ' Now lets display some relevant information about each device found
                    '


it then read what are the IPs on the network, then scan them one by one using

HEIOPENDevice(...)
etc..


Do i have to add PASCAL_HEICloseTransport(TP) after every unique IP ponctual scan? Because maybe my problem is that there was 4 PLC on the network... therefore maybe 1 port was being closed after a full loop..?! (or maybe HEIClose() ?)

Thanks for your help again!


MikeS

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 264
    • Host Engineering, Inc.
Re: Problem closing open port
« Reply #1 on: June 16, 2009, 10:56:44 AM »
the way it should work is like this:

heiopen
   heiopen transport
      an heiopendevice call for each ECOM you want to talk with
         []
         [the heiread, heiwrite, etc. until you're done]
         []
      an heiclosedevice for each heiopendevice
   one heiclosetransport
and one heiclose
     
Good design costs a lot. Bad design costs even more.