Announcement

Collapse
No announcement yet.

TCP/IP port testen ob connection möglich ist

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • TCP/IP port testen ob connection möglich ist

    Hallo,
    ich muss ein Programm schreiben welches ein TCP/IP port an einem Server testet ob dort eine Connection möglich ist.
    Bisher habe ich folgendes:

    Socket* s = 0;
    IPHostEntry* iphe = 0;
    iphe = Dns::Resolve("localhost");
    IPAddress* addr = new IPAddress(1);
    addr = addr->Parse("127.0.0.1");
    IPEndPoint* ipe = new IPEndPoint(addr, 5993);
    Socket* tmpS;
    try
    {
    // versuche zum GoldSync eine verbindung aufzubauen.
    tmpS = new Socket(ipe->AddressFamily, SocketType::Stream, ProtocolType::Tcp);
    tmpS->Connect(ipe);
    Thread::Sleep(6000);
    if (tmpS->Connected == false)
    {

    throw;
    }
    tmpS->Shutdown;
    tmpS->Close;
    }
    catch(...)
    ....

    Das funktioniert auch wenn überhaupt keine verbindung aufgebaut werden kann.
    Doch es kommt auch hin und wieder mal vor das sich diese Verbindung wie folgt verhält:
    telnet 192.168.10.251 5993
    Trying 192.168.10.251...
    Connected to 192.168.10.251.
    Escape character is '^]'.
    Connection closed by foreign host.

    Und das wird von dem code oben nicht erkannt.
    Wie stelle ich das an das er auch diese ausnahme erkennt?

    gruß
    Sven
Working...
X