Search code examples
delphi64-bitdelphi-10.3-riodata-stream

kbmmw Client: 64-bit request stream issue


I have developped a client-server application using 64-bit kbmmw package on Delphi 10.3 IDE. The 64-bit client application send the requests to server by SendRequest method (kbmmwClient class method) setting the request service name and the username properties. Internally the kbmmwClient library create a request stream (TkbmMWCustomRequestTransportStream class) , which will be sent to the server.

tRequestStream:=TkbmMWCustomRequestTransportStream(cStreamClass.Create(FTransport,FTransport.Info));
tRequestStream.RequestID:=rid;
tRequestStream.ServiceName:=AServiceName;
tRequestStream.Username:=FUsername;
--Begin my debug-----------------
debug('InternalSendRequest - tRequestStream.ServiceName: ' + tRequestStream.ServiceName);
debug('InternalSendRequest - tRequestStream. Username: ' + tRequestStream.Username);
t := tkbmmwmemorystream(tRequestStream.DataStream);
SetString(streamstring, PAnsiChar(t.Memory), t.Size);
write_debug('InternalSendRequest - tRequestStream - DataStream: ' + streamstring);
--End my debug

This is the debug result:

14/04/2020 15:50:32.226: InternalSendRequest - tRequestStream.ServiceName: reqservice
14/04/2020 15:50:32.226: InternalSendRequest - tRequestStream. Username: ANDAPI
14/04/2020 15:50:32.227: InternalSendRequest - tRequestStream - DataStream: Ìû¯
   STANDARDü     
   r e q s e r v i c e            A N D A P I             ÿÿÿÿ        €                    

Why are the characters of the service name (reqservice) and the username (ANDAPI) words interspersed with null characters? When I had used the 32-bit kbmmwClient, the request stream was sent in the correct format.


Solution

  • The ServiceName, UserName and many other strings are streamed as kbmMW strings. How exactly they are streamed depends on:

    1. Does the compiler support Unicode?
    2. Is the transport stream version >= 300?
    3. Is mwtsoUnicodeStrings set in the transport stream options?

    If Unicode is not supported, 8 bit non codepaged strings are sent (without zeroes). If point 2 and 3 is not matched, it is also sent as 8 bit non codepaged strings (simple downconversion from Unicode)

    So my guess is, if you are using the same Delphi version, that you, in your 32 bit code have specifically downgraded the transport stream version to be compatible with an older version of kbmMW?

    best regards Kim/C4D