Visual FoxPro
Visual FoxPro
Receive a Single Byte from a Socket
See more Socket/SSL/TLS Examples
Demonstrates Socket.ReceiveByte, which reads exactly one byte and stores its numeric value in the ReceivedInt property. The argument selects signed or unsigned interpretation.
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 Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loSocket
LOCAL lnBTls
LOCAL lnMaxWaitMs
LOCAL lnBUnsigned
lnSuccess = 0
loSocket = CreateObject('Chilkat.Socket')
* Connect to the server using TLS.
lnBTls = 1
lnMaxWaitMs = 5000
lnSuccess = loSocket.Connect("example.com",5000,lnBTls,lnMaxWaitMs)
IF (lnSuccess = 0) THEN
? loSocket.LastErrorText
RELEASE loSocket
CANCEL
ENDIF
* Read exactly one byte. Its numeric value is stored in the ReceivedInt property. Passing 1
* interprets the byte as unsigned (0 through 255); 0 interprets it as signed.
lnBUnsigned = 1
lnSuccess = loSocket.ReceiveByte(lnBUnsigned)
IF (lnSuccess = 0) THEN
? loSocket.LastErrorText
RELEASE loSocket
CANCEL
ENDIF
? "Received byte value: " + STR(loSocket.ReceivedInt)
RELEASE loSocket