Autor Beitrag
Georg08
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 155
Erhaltene Danke: 6

Win XP
Delphi 7.0 Personal
BeitragVerfasst: So 05.12.10 20:02 
Hallo Community,

Ich aheb mir ein Php-Script geschreiben, dass einen Host anfragt mit fsockopen und wenn dieser (nicht) erreichbar ist einen jeweiligen Text ausgibt
ausblenden Quelltext
1:
2:
3:
4:
5:
$socket1 = @fsockopen($host, $port, $errorno, $errorstr, 5);
if($socket1 >=1) {
  echo "Online" }
else {
  echo "Offline" }

Ich würde das ganze jetzt aber geine in einem Programm realisieren. Zuerst habe ich es mit einem IdIcmpClient versucht, da ich einen Ping machen wollte, aber das ging schief, da er auch wenn der Server noch nicht wirklich Online ist eine Antwort gibt.

Meine Frage wäre jetzt, ob es ein Equivalent in Delphi zu fsockopen gibt...


Danke
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19315
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: So 05.12.10 20:28 
Bei Delphi 7 wie in deinem Profil steht müsste es TSocketClient geben.

Und bei Indy könntest du z.B. TIdTcpClient benutzen.
Georg08 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 155
Erhaltene Danke: 6

Win XP
Delphi 7.0 Personal
BeitragVerfasst: So 05.12.10 20:33 
Danke
Habe ungefähr zeitgleich eine lösung gefunden :D
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
uses
[...], ScktComp;

[...]

procedure CheckSocket;
var
  Client: TClientSocket;
begin
  Client := TClientSocket.Create(self);
  Client.ClientType := ctBlocking;
  Client.Host := '[IP]';
  Client.Port := [PORT];
  try
    Client.Open;
    Client.Close;
    ConnectionState := SrvOnline;
    Application.ProcessMessages;
  except
    Application.ProcessMessages;
    ConnectionState := SrvOffline;
  end;
end;


Als Anregung dafür hatte ich folgendes gefunden:
www.lobnan.de/coding/internetverkehr.html (Beispiel2: Der Portscanner)
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: So 05.12.10 21:29 
Moin!

Du solltest allerdings dringend noch den TClientSocket wieder freigeben, sonst hast du a) ein Speicherleck und b) wirft dir Windows irgendwann ein EOutOfResources um die Ohren, weil die Socket-Handles ausgehen... :idea:

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.