Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(PowerBuilder) TCP Socket Send Byte and Receive ByteDemonstrates the Chilkat Socket ReceiveByte and SendByte method.
integer li_rc oleobject loo_Sock integer li_UseTls integer li_Port integer li_MaxWaitMs integer li_Success integer li_TreatAsUnsignedInt // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. loo_Sock = create oleobject // Use "Chilkat_9_5_0.Socket" for versions of Chilkat < 10.0.0 li_rc = loo_Sock.ConnectToNewObject("Chilkat.Socket") if li_rc < 0 then destroy loo_Sock MessageBox("Error","Connecting to COM object failed") return end if // -------------------------------------------------------------------- // This example uses the public TCP echo service at https://tcpbin.com/ // -------------------------------------------------------------------- li_UseTls = 0 li_Port = 4242 li_MaxWaitMs = 5000 li_Success = loo_Sock.Connect("tcpbin.com",li_Port,li_UseTls,li_MaxWaitMs) if li_Success = 0 then Write-Debug loo_Sock.LastErrorText destroy loo_Sock return end if // Wait a max of 2 seconds for a response.. loo_Sock.MaxReadIdleMs = 2000 // Send a byte. loo_Sock.SendByte(96) // The tcpbin.com echo server only echoes after receiving an LF (linefeed char) loo_Sock.SendByte(10) // The echo server will echo back whatever is sent to it. // We should be able to read the same byte back.. // After successfully reading, the byte value is available in the ReceivedInt property. li_TreatAsUnsignedInt = 1 li_Success = loo_Sock.ReceiveByte(li_TreatAsUnsignedInt) if li_Success = 0 then Write-Debug loo_Sock.LastErrorText destroy loo_Sock return end if // Let's look at the value of the byte received. It should be 96. Write-Debug string(loo_Sock.ReceivedInt) // The echo server also echoed the LF back. li_Success = loo_Sock.ReceiveByte(li_TreatAsUnsignedInt) // Assuming success.. // Should be decimal 10. Write-Debug string(loo_Sock.ReceivedInt) destroy loo_Sock |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.