Delphi Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript

Delphi Examples

Bounced Mail
Bz2
Character Encoding
CSV
Digital Certificates
Digital Signatures
DH Key Exchange
DSA
Email
Email Object
FTP
HTML-to-XML
HTTP
IMAP
Encryption
MHT / HTML Email
POP3
RSA
S/MIME
SMTP
Socket
Spider
SFTP
SSH
SSH Key
SSH Tunnel
String
Tar
Upload
XML
XMP
Zip Compression

More Examples...
Byte Array
FileAccess
RSS
Atom
Self-Extractor
Service
PPMD
Deflate

Unreleased...
Bzip2
LZW
Icon

Type Conversion

 

Article: Understanding COM References in Delphi

Send File over Socket

Demonstrates how to send a file over a TCP/IP socket.

Download Chilkat FileAccess ActiveX (freeware)

Download Chilkat Socket ActiveX

uses
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    Dialogs, StdCtrls,
    CHILKATFILEACCESSLib_TLB,
    CHILKATSOCKETLib_TLB,
    OleCtrls;

...

procedure TForm1.Button1Click(Sender: TObject);
var
socket: TChilkatSocket;
success: Integer;
fac: TCkFileAccess;
fileSize: Integer;
fileData: Array of Byte;
ssl: Integer;
maxWaitMillisec: Integer;

begin
socket := TChilkatSocket.Create(Self);

success := socket.UnlockComponent('Anything for 30-day trial');
if (success <> 1) then
  begin
    ShowMessage('Failed to unlock component');
    Exit;
  end;

fac := TCkFileAccess.Create(Self);

//  We'll send a GIF file.  First get the size of the file:

fileSize := fac.FileSize('dude.gif');
if (fileSize < 0) then
  begin
    ShowMessage('Failed to get file size');
    Exit;
  end;

//  Load the file into memory:

fileData := fac.ReadEntireFile('dude.gif');

//  Connect to the program at some host:port that is expecting
//  to receive the file.  In this case, the receiver is at
//  localhost:5555
ssl := 0;
maxWaitMillisec := 20000;
success := socket.Connect('localhost',5555,ssl,maxWaitMillisec);
if (success <> 1) then
  begin
    ShowMessage(socket.LastErrorText);
    Exit;
  end;

//  Set maximum timeouts for reading an writing (in millisec)
socket.MaxReadIdleMs := 10000;
socket.MaxSendIdleMs := 10000;

//  Send the byte count:
success := socket.SendCount(fileSize);
if (success <> 1) then
  begin
    ShowMessage(socket.LastErrorText);
    Exit;
  end;

//  Send the file data.
success := socket.SendBytes(fileData);
if (success <> 1) then
  begin
    ShowMessage(socket.LastErrorText);
    Exit;
  end;

//  Close the connection with the server
//  Wait a max of 20 seconds (20000 millsec)
socket.Close(20000);
end;

 

Need a specific example? Send a request to support@chilkatsoft.com

© 2000-2008 Chilkat Software, Inc. All Rights Reserved.

Mail Component · .NET Email Component · XML Parser