Programming Examples

ChilkatHOMEASPVisual BasicVB.NETC#CC++MFCDelphiFoxProJavaPerlPythonRubySQL ServerVBScript

PHP ActiveX Examples

Bounced Mail
Bz2
Certificates/Keys
Charset
CSV
DKIM / DomainKey
Diffie-Hellman
DSA
Email Object
Encryption
FileAccess
FTP
HTML Conversion
HTTP
IMAP
MHT / HTML Email
MIME
NTLM
POP3
RSA
SMTP
Socket
Spider
SSH Key
SSH
SSH Tunnel
SFTP
Tar
Upload
XML
Zip
Amazon S3


 

 

 

 

 

 

 

 

Send File over Socket

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

Download Chilkat FileAccess ActiveX (freeware)

Download Chilkat Socket ActiveX

<?php

$socket = new COM("Chilkat.Socket");

$success = $socket->UnlockComponent('Anything for 30-day trial');
if ($success != true) {
    print 'Failed to unlock component' . "\n";
    exit;
}

$fac = new COM("Chilkat.FileAccess");

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

$fileSize = $fac->FileSize('dude.gif');
if ($fileSize < 0) {
    print 'Failed to get file size' . "\n";
    exit;
}

//  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 = false;
$maxWaitMillisec = 20000;
$success = $socket->Connect('localhost',5555,$ssl,$maxWaitMillisec);
if ($success != true) {
    print $socket->lastErrorText() . "\n";
    exit;
}

//  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 != true) {
    print $socket->lastErrorText() . "\n";
    exit;
}

//  Send the file data.
$success = $socket->SendBytes($fileData);
if ($success != true) {
    print $socket->lastErrorText() . "\n";
    exit;
}

//  Close the connection with the server
//  Wait a max of 20 seconds (20000 millsec)
$socket->Close(20000);
?>

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

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