MOGSY Posted August 20, 2020 Share Posted August 20, 2020 Hi I am using an idHttpServer to communicate with external apps. After receiving any message UniGui does not recognising any of the forms or frames. Please have a look at the attached sample program. I have included a test client "MDC_ClientTester.exe" which will send a JSON string to server on port 9290. The communication is fine. except after receiving a message UniGui gets confused. I appreciate any help or suggestion to overcome this issue please. Thank you. Test.7z Quote Link to comment Share on other sites More sharing options...
MOGSY Posted August 24, 2020 Author Share Posted August 24, 2020 Hi Has anyone have a solution for receiving JSON message from another application. A UniGui application that can receive information from outside world. Many thanks. Quote Link to comment Share on other sites More sharing options...
Mehmet Emin Posted August 24, 2020 Share Posted August 24, 2020 (edited) Hi, Your method of handling an external http request is not correct for a uniGUI server project. Do it this way: Use UniGUIServerModuleHTTPCommand event to handle json requests. procedure TUniServerModule.UniGUIServerModuleHTTPCommand( ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo; var Handled: Boolean); I hope the following example code helps: if ARequestInfo.URI = URI_device_getcommand then begin Handled := True; // SET. true THIS IS IMPORTANT the rest fo the code is a sample: DevicePostString := nil; DeviceJSon := nil; CommandJSon := nil; LConnection := nil; LDevice := nil; try DevicePostString := TStringStream.Create(''); DevicePostString.CopyFrom(ARequestInfo.PostStream, ARequestInfo.PostStream.Size); DeviceJSon := TJSonObject.ParseJSONValue(DevicePostString.DataString); if DeviceJSon.TryGetValue<String>(JSON_PATH_DeviceCode, LDeviceCode) then begin LDeviceStatusInt := 0; LPowerOnTime := 0; LPowerOnMinutes := 0; DeviceJSon.TryGetValue<String>(JSON_PATH_MACAddress, LMACAddress); DeviceJSon.TryGetValue<Integer>(JSON_PATH_DeviceStatus, LDeviceStatusInt); DeviceJSon.TryGetValue<Integer>(JSON_PATH_PowerOnMinutes, LPowerOnMinutes); DeviceJSon.TryGetValue<String>(JSON_PATH_PowerOnTime, LPowerOnTimeStr); TryISO8601ToDate(LPowerOnTimeStr, LPowerOnTime, False); LDeviceStatus := TDeviceStatus(LDeviceStatusInt); LConnection := TFDConnection.Create(nil); LConnection.ConnectionDefName := CONNECTION_DEF_NAME; LConnection.Open; LDevice := TZDEVICE.CreateWithConnection(LConnection); with LDevice do begin Edited August 24, 2020 by Mehmet Emin fixed typo Quote Link to comment Share on other sites More sharing options...
MOGSY Posted August 24, 2020 Author Share Posted August 24, 2020 Thanks great help. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.