Download source code

function TForm1.GetWakeUpPacket(const AMac: string): TBytes;
var
  i, j: Integer;
begin
  SetLength(Result, 102);
 
  for i := 0 to 5 do
  begin
    Result[i] := $FF;
  end;
 
  for i := 0 to 15 do
  begin
     for j := 0 to 5 do
     begin
       Result[6 + i * 6 + j] := HexToByte(AMac[3 * j + 1] + AMac[3 * j + 2]);
     end;
  end;
end;
 
procedure TForm1.btnWakeUpClick(Sender: TObject);
var
  client: TclUdpClientConnection;
begin
  client := TclUdpClientConnection.Create();
  StartupSocket();
  try
 
    client.NetworkStream := TclNetworkStream.Create();
 
    client.Open('255.255.255.255', 2110);
    client.Broadcast();
 
    client.WriteBytes(GetWakeUpPacket(edtMAC.Text));
  finally
    client.Free();
    CleanupSocket();
  end;
 
  ShowMessage('Done');
end;

Article ID: 54, Created On: 7/12/2013, Modified: 7/12/2013