Hi, I need to send a json text that contains a base64 encoded image. Problem is when I attempt to do this the app crashes or just freezes forever. I've set the writetimeout to 1 minute and it just crashes after that 1 minute or loses connection to the server. I'm attempting this on android. Is there a better way I can send and receive data from the server that contains a bitmap? My code is as follows:
Okay I did some testing. Even when sending the json data through a TStringStream and then using OnBinary to parse it the app Gets a "Connection Closed Gracefully" when trying to send something.
Hi again. I apologize for my rambling. I have solved the problem but I believe to have found a bug. The issue was on my end when I tried adding the base64 image to the database on the server. I did not specify the param size when trying to add the base64. See image for fix.
Now on to the bug. Before I fixed it the websocket server would disconnect the websocket client when the exception was called and not catched. It would then not let the client reconnect until the client has been restarted. (See screenshot)
FIX
Will not allow you to reconnect unless client is restarted.
I've done a simple test using the following code to send a Text message
var
i: integer;
s: string;
begin
for i := 1 to 10000000 do
s := s + '0';
WSClient.WriteData(s);
I connect to demo server which echoes the message (http://www.esegece.com:5414) and works well, it sends the message and is received correctly.
Which is the size of the message you are sending? The message is received by server? or the connection is blocked while writing?
Check if you receive something in the server when android sends the message, maybe is something related with the size of the message.
Error 22 Invalid argument usually means a problem while binding to a IP/Port, I can't reproduce here, I've put an exception in OnMessage event of server and if WatchDog is enabled it recovers the connection automatically. The same if WatchDog is enabled and after it's disconnected, I set Active := True, it works well.
When you say client restarted, you mean Android application is restarted or the Android device is restarted?
Error 22 Invalid argument usually means a problem while binding to a IP/Port, I can't reproduce here, I've put an exception in OnMessage event of server and if WatchDog is enabled it recovers the connection automatically. The same if WatchDog is enabled and after it's disconnected, I set Active := True, it works well.
When you say client restarted, you mean Android application is restarted or the Android device is restarted?
Kind regards,
Sergio
I meant I need to restart the app.
The data being sent is much larger.
Currently how this happens is:
The client uploads large binary data <2mb
The server fires the on binary event and then sends that data and the connection parameter to another procedure to be parsed and then added to the database. Issue with this is when that gets an exception without catching it it will then disconnect the client and the client fails to reconnect with the error in the image i sent in the post above.