Search the Community
Showing results for tags 'php c++ sockets tcp-ip'.
-
Hey guys, I need to rewrite a example of sockets TCP/IP communication done in c++ or delphi(have this 2 examples) to PHP, but have a problem with function memcpy(c++)/move(delphi) and with the structures used in both languages. in both cases i have this 2 structures: (struct from delphi) SPMSifHdr = packed record ui32Synch1: Longword; ui32Synch2: Longword; ui16Version: Word; ui32Cmd: Longint; ui32BodySize: Longint; end; SPMSifRegisterMsg = packed record hdr1: SPMSifHdr; szLicense: Array[0..19] of char; szApplName: Array[0..19] of char; nRet: Longint; end; Code used to send message to server: procedure TForm1.btnRegisterClick(Sender: TObject); var RegMsg: SPMSifRegisterMsg; byteMsg: Array[0..(sizeof(SPMSifRegisterMsg) - 1)] of byte; begin FillChar(RegMsg, SizeOf(RegMsg), 0); SetHeader(CMD_REGISTER, RegMsg.hdr1); //Set header information StrPCopy(RegMsg.szLicense, LicEdit.Text); //build data to structure StrPCopy(RegMsg.szApplName, ApplEdit.Text); Move(RegMsg, byteMsg, sizeof(SPMSifRegisterMsg)); //copy structure to bytearray ClientSocket1.Socket.SendBuf(byteMsg, sizeof(SPMSifRegisterMsg)); //send the data end; Problems: 1º - First in PHP how i can represent one structure like are used in c++ or delphi? Note: Remember i need pass this kind of structure in socket_send method, in 'buf' param) 2º - In PHP what function do the same job like memcpy(c++)/move(delphi)? Note: For me it's not important put the information necessary to send directly to the memory block, but it's important convert the information to hex(?) like happens in c++ or delphi. Structure with information before memcpy: Result of memcpy function/information send to server: I'm desperate with this situation, for second problem i've tried used the function "pack()" but i have no ideia what format to use, because i don't now what is the format they need to receive. In php dont exist structures so do you think this can be a right solution so send the information??? $packed = pack('I', $pMsgBlock->hdr1) .pack('I', $pMsgBlock->szLicense) .pack('I', $pMsgBlock->szAppname) .pack('I', $pMsgBlock->nRet); If necessary i can give more information.