Delphi-PRAXiS
Seite 2 von 2     12   

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Netzwerke (https://www.delphipraxis.net/14-netzwerke/)
-   -   Delphi Magic Packet richtig zusammenstellen (https://www.delphipraxis.net/134498-magic-packet-richtig-zusammenstellen.html)

sx2008 23. Mai 2009 17:32

Re: Magic Packet richtig zusammenstellen
 
Wie ist denn die Send-Methode deklariert? Etwa so:
Delphi-Quellcode:
procedure Send(const buffer);
Dann muss man so senden:
Delphi-Quellcode:
Send(Data[1]); // man beachte das [1]

Neutral General 23. Mai 2009 17:36

Re: Magic Packet richtig zusammenstellen
 
Ich schätze es ist wirklich als Send(const S: String) deklariert. (const Buffer) wäre ohne Längenparameter etwas kritisch..

sx2008 23. Mai 2009 17:39

Re: Magic Packet richtig zusammenstellen
 
Zitat:

Zitat von Neutral General
Ich schätze es ist wirklich als Send(const S: String) deklariert. (const Buffer) wäre ohne Längenparameter etwas kritisch..

Stimmt. :pale:

stev-e87 23. Mai 2009 17:56

Re: Magic Packet richtig zusammenstellen
 
So, hab vor lauter Unverständnis noch mal die Delphi 6 IDE zum Laufen gebracht und was soll ich sagen, damit funktioniert es!
Kanns quasi nur noch an der Indy Komonente liegen oder arbeitet Delphi 2009 in Hinsicht auf das Problem anders? Denke doch nicht.

PS.: Die Deklaration ist Const AData:String

mkinzler 23. Mai 2009 17:59

Re: Magic Packet richtig zusammenstellen
 
String D6 = AnsiString
String D2009 = UnicodeString

Char D6 = AnsiChar ( 8Bit)
Char D2009 = WideChar ( 16Bit)

stev-e87 23. Mai 2009 19:06

Re: Magic Packet richtig zusammenstellen
 
Hab data im Deklarationsteil mal als AnsiString vorgegeben, das Ergebnis bleibt...

Apollonius 23. Mai 2009 19:32

Re: Magic Packet richtig zusammenstellen
 
Das kann auch nichts ändern, wenn Indy mit Unicode arbeitet. Man sollte eben binäre Daten nicht als String senden.

paritycheck 23. Mai 2009 20:35

Re: Magic Packet richtig zusammenstellen
 
Hi,
hab zwar kein Delphi 2009 zum testen aber vielleicht funktioniert folgender Code:

Delphi-Quellcode:
uses winsock;
....
function WakeOnLan(szMac: String): Boolean;
var
  sock         : TSocket;
  addr         : TSockAddrIn;
  WSA          : TWSAData;
  buf          : array[0..101] of byte;
  HWAddr       : array[0..5] of byte;
  bTrue        : Boolean;
  P            : PChar;
  I            : Integer;
  Code         : Integer;
  szTmp        : String;
  dwRet        : Cardinal;
  Seperatorcount: Integer;
begin
  bTrue:= True;
  Result:= False;

  Seperatorcount:= 0;
  if (length(szMac) <> 17) and (length(szMac) <> 12) then Exit;
  for I:= 1 to length(szMac) do begin
      if not (szMac[I] in ['A'..'F','0'..'9','a'..'f', '-', ':']) then Exit;
      if (szMac[i] in ['-', ':']) then begin
         inc(Seperatorcount);
         if Seperatorcount > 5 then Exit;
      end;
  end;

  szTmp:= szMac;
  repeat
    I:= pos('-', szTmp);
    if I > 0 then Delete(szTmp, I, 1);
  until
    I <= 0;
  repeat
    I:= pos(':', szTmp);
    if I > 0 then Delete(szTmp, I, 1);
  until
    I <= 0;

  FillChar(buf, 6, $FF);
  P:= PChar(szTmp);
  for I:= 0 to 5 do begin
      val('$'+P^+(P+1)^, HWAddr[i], Code);
      inc(P,2);
  end;
  for I:= 0 to 15 do
      move(HWAddr, buf[6+(i*6)], 6);

  dwRet:= WSAStartup((2 shl 8)+1, WSA);
  if dwRet = 0 then begin
     sock:= socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
     if sock <> INVALID_SOCKET then begin
        if setsockopt(sock, SOL_SOCKET, SO_BROADCAST, pchar(@bTrue), sizeof(bTrue)) = 0 then begin
           FillChar(addr, sizeof(addr), 0);
           addr.sin_family:= AF_INET;
           addr.sin_addr.s_addr:= INADDR_BROADCAST;
           addr.sin_port:= htons(60000);
           dwRet:= sendto(sock, buf, sizeof(buf), 0, addr, sizeof(addr));
           Result:= (dwRet=sizeof(buf));
        end;
     end;
     WSACleanup;
  end;
end;

himitsu 23. Mai 2009 21:25

Re: Magic Packet richtig zusammenstellen
 
[durchstreich]
Delphi-Quellcode:
Data := #$00FF#$00FF#$00FF#$00FF#$00FF#$00FF
[/durchstreich]
edit: Blödsinn

Problem: siehe http://www.delphipraxis.net/internal...t.php?t=153308


Delphi-Quellcode:
var a: AnsiString;
  s: String;
begin
s := #$FF#$FF#$FF#$FF#$FF#$FF;
a := s;
if ord(s[1]) = ord(a[1]) then ;
Beides 255


welchen Zeichensatz/Kodierung verwendeten denn Indy?

stev-e87 24. Mai 2009 07:01

Re: Magic Packet richtig zusammenstellen
 
Zitat:

Zitat von paritycheck
Hi,
hab zwar kein Delphi 2009 zum testen aber vielleicht funktioniert folgender Code:

Delphi-Quellcode:
uses winsock;
....
function WakeOnLan(szMac: String): Boolean;
var
  sock         : TSocket;
  addr         : TSockAddrIn;
  WSA          : TWSAData;
  buf          : array[0..101] of byte;
  HWAddr       : array[0..5] of byte;
  bTrue        : Boolean;
  P            : PChar;
  I            : Integer;
  Code         : Integer;
  szTmp        : String;
  dwRet        : Cardinal;
  Seperatorcount: Integer;
begin
  bTrue:= True;
  Result:= False;

  Seperatorcount:= 0;
  if (length(szMac) <> 17) and (length(szMac) <> 12) then Exit;
  for I:= 1 to length(szMac) do begin
      if not (szMac[I] in ['A'..'F','0'..'9','a'..'f', '-', ':']) then Exit;
      if (szMac[i] in ['-', ':']) then begin
         inc(Seperatorcount);
         if Seperatorcount > 5 then Exit;
      end;
  end;

  szTmp:= szMac;
  repeat
    I:= pos('-', szTmp);
    if I > 0 then Delete(szTmp, I, 1);
  until
    I <= 0;
  repeat
    I:= pos(':', szTmp);
    if I > 0 then Delete(szTmp, I, 1);
  until
    I <= 0;

  FillChar(buf, 6, $FF);
  P:= PChar(szTmp);
  for I:= 0 to 5 do begin
      val('$'+P^+(P+1)^, HWAddr[i], Code);
      inc(P,2);
  end;
  for I:= 0 to 15 do
      move(HWAddr, buf[6+(i*6)], 6);

  dwRet:= WSAStartup((2 shl 8)+1, WSA);
  if dwRet = 0 then begin
     sock:= socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
     if sock <> INVALID_SOCKET then begin
        if setsockopt(sock, SOL_SOCKET, SO_BROADCAST, p[color=#ff0000]ansi[/color]char(@bTrue), sizeof(bTrue)) = 0 then begin
           FillChar(addr, sizeof(addr), 0);
           addr.sin_family:= AF_INET;
           addr.sin_addr.s_addr:= INADDR_BROADCAST;
           addr.sin_port:= htons(60000);
           dwRet:= sendto(sock, buf, sizeof(buf), 0, addr, sizeof(addr));
           Result:= (dwRet=sizeof(buf));
        end;
     end;
     WSACleanup;
  end;
end;

Guten morgen...

Danke vielmals für die Bemühungen, mit obiger rot markierter Änderung hat es funktioniert ;)


Alle Zeitangaben in WEZ +1. Es ist jetzt 17:00 Uhr.
Seite 2 von 2     12   

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz