Chilkat
HOME
Android™
ASP
Visual Basic
VB.NET
C#
iOS (IPhone)
Objective-C
C++
C
MFC
Delphi
FoxPro
Java
Perl
PHP Extension
PHP ActiveX
Python
PowerShell
Ruby
SQL Server
VBScript
Send File over SocketDemonstrates how to send a file over a TCP/IP socket.
set socket = CreateObject("Chilkat.Socket") success = socket.UnlockComponent("Anything for 30-day trial") If (success <> 1) Then MsgBox "Failed to unlock component" WScript.Quit End If set fac = CreateObject("Chilkat.FileAccess") ' We'll send a GIF file. First get the size of the file: fileSize = fac.FileSize("dude.gif") If (fileSize < 0) Then MsgBox "Failed to get file size" WScript.Quit End If ' 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 MsgBox socket.LastErrorText WScript.Quit End If ' 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 MsgBox socket.LastErrorText WScript.Quit End If ' Send the file data. success = socket.SendBytes(fileData) If (success <> 1) Then MsgBox socket.LastErrorText WScript.Quit End If ' Close the connection with the server ' Wait a max of 20 seconds (20000 millsec) socket.Close 20000 |
© 2000-2010 Chilkat Software, Inc. All Rights Reserved.