Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

DataFlex Examples

Web API Categories

ASN.1
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text

HTTP
HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
MS Storage Providers
Microsoft Graph
NTLM
OAuth1
OAuth2
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
PDF Signatures
PEM
PFX/P12
POP3
PRNG
REST
REST Misc
RSA
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
SharePoint
Socket/SSL/TLS
Spider
Stream
Tar Archive
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl

 

 

 

(DataFlex) Accept Connection on Socket

Demonstrates how to create a TCP/IP socket, listen on a port, accept an incoming connection, and send a "Hello World" message to the client.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

Use ChilkatAx-9.5.0-win32.pkg

Procedure Test
    Handle hoListenSocket
    Boolean iSuccess
    Variant vConnectedSocket
    Handle hoConnectedSocket
    String sTemp1
    Boolean bTemp1

    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    Get Create (RefClass(cComChilkatSocket)) To hoListenSocket
    If (Not(IsComObjectCreated(hoListenSocket))) Begin
        Send CreateComObject of hoListenSocket
    End

    // 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.
    Get ComBindAndListen Of hoListenSocket 5555 25 To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoListenSocket To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    // Get the next incoming connection
    // Wait a maximum of 20 seconds (20000 millisec)

    Get ComAcceptNextConnection Of hoListenSocket 20000 To vConnectedSocket
    If (IsComObject(vConnectedSocket)) Begin
        Get Create (RefClass(cComChilkatSocket)) To hoConnectedSocket
        Set pvComObject Of hoConnectedSocket To vConnectedSocket
    End
    Get ComLastMethodSuccess Of hoListenSocket To bTemp1
    If (bTemp1 = False) Begin
        Get ComLastErrorText Of hoListenSocket To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    // Set maximum timeouts for reading an writing (in millisec)
    Set ComMaxReadIdleMs Of hoConnectedSocket To 10000
    Set ComMaxSendIdleMs Of hoConnectedSocket To 10000

    // Send a "Hello World!" message to the client:
    Get ComSendString Of hoConnectedSocket "Hello World!" To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoConnectedSocket To sTemp1
        Showln sTemp1
        Send Destroy of hoConnectedSocket
        Procedure_Return
    End

    // Close the connection with the client.
    // Wait a max of 20 seconds (20000 millsec)
    Get ComClose Of hoConnectedSocket 20000 To iSuccess

    Showln "success!"


End_Procedure

 

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