Chilkat HOME ASP Visual Basic VB.NET C# Visual C++ C MFC Delphi FoxPro Java Perl PHP Python Ruby SQL Server VBScript
|
Receive File on SocketDemonstrates how to listen for an incoming socket connection and receive a file. The received file is saved to disk.
LOCAL loListenSocket LOCAL lnSuccess LOCAL loConnectedSocket LOCAL lnFileSize LOCAL loFileData LOCAL loFac loListenSocket = CreateObject('Chilkat.Socket') lnSuccess = loListenSocket.UnlockComponent("Anything for 30-day trial") IF (lnSuccess <> 1) THEN =MESSAGEBOX("Failed to unlock component") QUIT ENDIF * Bind to a port and listen for incoming connections: * This example will listen at port 5555 and allows for a backlog * of 25 pending connection requests. lnSuccess = loListenSocket.BindAndListen(5555,25) IF (lnSuccess <> 1) THEN =MESSAGEBOX(loListenSocket.LastErrorText) QUIT ENDIF * Get the next incoming connection * Wait a maximum of 20 seconds (20000 millisec) loConnectedSocket = loListenSocket.AcceptNextConnection(20000) IF (loConnectedSocket = NULL ) THEN =MESSAGEBOX(loListenSocket.LastErrorText) QUIT ENDIF * Set maximum timeouts for reading an writing (in millisec) loConnectedSocket.MaxReadIdleMs = 10000 loConnectedSocket.MaxSendIdleMs = 10000 * Receive the byte count of the file data that is forthcoming: lnFileSize = loConnectedSocket.ReceiveCount() IF (lnFileSize < 0) THEN =MESSAGEBOX(loConnectedSocket.LastErrorText) QUIT ENDIF loFileData = loConnectedSocket.ReceiveBytesN(lnFileSize) IF (loConnectedSocket.LastMethodFailed = 1) THEN =MESSAGEBOX(loConnectedSocket.LastErrorText) QUIT ENDIF * Close the connection. * Wait a max of 20 seconds (20000 millsec) loConnectedSocket.Close(20000) * Write the received data to a file. * This example receives a GIF image file. loFac = CreateObject('Chilkat.FileAccess') lnSuccess = loFac.WriteEntireFile("received.gif",loFileData) IF (lnSuccess <> 1) THEN =MESSAGEBOX(loListenSocket.LastErrorText) QUIT ENDIF =MESSAGEBOX("success!") |
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2007 Chilkat Software, Inc. All Rights Reserved.
Mail Component · .NET Email Component · ASP Mail Component · XML Parser