1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

  2. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

How to use Windows API 'GetTcpTable' to find a avaiable tcp port?

Discussão em 'StackOverflow' iniciado por fdantas, Setembro 28, 2020.

  1. fdantas

    fdantas Administrator Moderador

    I tried to use .Net to get a available port, but I got error 5729: Incompatible datatypes found during runtime conversion. (5729)

    I Don't know where I shoud explicit the expressions

    Beneath is my demo code using .Net:

    DEFINE VARIABLE htPorts AS System.Collections.Hashtable.
    DEFINE VARIABLE IPProperties AS System.Net.NetworkInformation.IPGlobalProperties.
    DEFINE VARIABLE connection AS System.Net.NetworkInformation.TcpConnectionInformation EXTENT.
    DEFINE VARIABLE ix AS INTEGER NO-UNDO .
    DEFINE VARIABLE iPort AS INTEGER INITIAL 12121 NO-UNDO .

    IPProperties = System.Net.NetworkInformation.IPGlobalProperties:GetIPGlobalProperties().
    connection = IPProperties:GetActiveTcpConnections().
    htPorts = NEW System.Collections.Hashtable().
    DO ix = 1 TO EXTENT(connection):
    IF NOT htPorts:Contains(connection[ix]:LocalEndPoint:port) THEN
    htPorts:Add(connection[ix]:LocalEndPoint:port,0).
    IF connection[ix]:RemoteEndPoint:Address:ToString() = "127.0.0.1":U THEN DO:
    IF NOT htPorts:Contains(connection[ix]:RemoteEndPoint:port) THEN
    htPorts:Add(connection[ix]:RemoteEndPoint:port, 0).
    END.
    END.

    ix = 0.
    DO WHILE ix < 10:
    ix = ix + 1.
    IF htPorts:Contains(iPort) THEN
    DO:
    iPort = iPort + 1.
    END.
    ElSE LEAVE.
    END.
    MESSAGE iport.


    Now I'm trying to use windows api 'GetTcpTable', but I don't know how to prepare the data structure 'PMIB_TCPTABLE'.

    Continue reading...

Compartilhe esta Página