Lianja
Lianja
Receive a 32-bit Integer from a Socket
See more Socket/SSL/TLS Examples
Demonstrates Socket.ReceiveInt32, which reads exactly four bytes as a signed 32-bit integer and stores the result in the ReceivedInt property. Byte order is selectable.
Background. Fixed-size integers and length prefixes are common building blocks for application-defined binary protocols. Byte order is selectable, with big-endian being network byte order.
Chilkat Lianja Downloads
llSuccess = .F.
loSocket = createobject("CkSocket")
// Connect to the server using TLS.
llBTls = .T.
lnMaxWaitMs = 5000
llSuccess = loSocket.Connect("example.com",5000,llBTls,lnMaxWaitMs)
if (llSuccess = .F.) then
? loSocket.LastErrorText
release loSocket
return
endif
// Read exactly four bytes as a signed 32-bit integer and store the result in the ReceivedInt
// property. The argument selects byte order (.T. = big-endian, network byte order).
llBBigEndian = .T.
llSuccess = loSocket.ReceiveInt32(llBBigEndian)
if (llSuccess = .F.) then
? loSocket.LastErrorText
release loSocket
return
endif
? "Received 32-bit integer: " + str(loSocket.ReceivedInt)
release loSocket