M
MBeynon
Guest
Hello, I have a requirement to connect via a raw socket connection to a server that is expecting data in a certain structure. The connection is not a problem but the sending of the inital login request is proving problematic. The API for the software I wish to connect to uses hex values, added together to build a particular request identifier, in this case the request to login: DEFINE VARIABLE CSI AS INT64 INIT 0X80000000 NO-UNDO. DEFINE VARIABLE SIF_GENERAL AS INT64 INIT 0X08000000 NO-UNDO. DEFINE VARIABLE SIS_LOGIN AS INT64 INIT 0X00000100 NO-UNDO. DEFINE VARIABLE CSI_LOGIN AS INT64 NO-UNDO. /* Request header */ ASSIGN CSI_LOGIN = CSI + SIF_GENERAL + SIS_LOGIN. RUN SocketConnect(INPUT "46.38.160.140", INPUT 1401, INPUT "", INPUT 0, INPUT lvcUserName, INPUT hexadecimal(CSI_LOGIN) , /* Add the hexadecimal values */ INPUT EncryptData(lvcPassword), OUTPUT lvlErrorMsg). So, for CSI_LOGIN we have 0X80000000 + 0X08000000 + 0X00000100 which gives us 0X88000100 using the Hexadecimal function below. This is then inserted into the sockets MEMPTR. /* found this on this forum I think! */ FUNCTION Hexadecimal RETURN CHARACTER (lvcHex AS INT64): DEF VAR hNum AS CHARACTER NO-UNDO EXTENT 16 INITIAL [ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E' ]. DEF VAR chex AS CHARACTER NO-UNDO. DEF VAR pres AS INT64 NO-UNDO. DEF VAR pmod AS INT64 NO-UNDO. pres = lvcHex. DO WHILE pres 0: ASSIGN pmod = ( pres MOD 16 ) chex = hNum[pmod + 1] + chex pres = ( pres - pmod ) / 16. END. RETURN chex. END FUNCTION. The only way to do the above as far as I’m aware is using an INT64 value which is 8 bytes (64bits), not 4 and 32 as required by the "listening" machine's software. So, in order to get this to work, I need to pass 0X88000100 across in the MEMPTR represented as an INT (32) not INT64. Have I missed something really obvious here? Thanks, Mark.
Continue reading...
Continue reading...