By Adriaan on Tuesday, 24 November 2020
Posted in General
Replies 10
Likes 0
Views 2.8K
Votes 0
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:

1.png

convert.png
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.
·
3 years ago
·
0 Likes
·
0 Votes
·
0 Comments
·
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
fixed.png


Will not allow you to reconnect unless client is restarted.
error.jpg
·
3 years ago
·
0 Likes
·
0 Votes
·
0 Comments
·
Hello,

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.

Kind regards,
Sergio
·
3 years ago
·
0 Likes
·
0 Votes
·
0 Comments
·
Hi,

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
·
3 years ago
·
0 Likes
·
0 Votes
·
0 Comments
·
Hi,

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:

  1. The client uploads large binary data <2mb
  2. 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.


I will try to make an example project for you.
·
3 years ago
·
0 Likes
·
0 Votes
·
0 Comments
·
I can only reproduce this on android. Windows does not have this issue but I have attached the project to reproduce this.
·
3 years ago
·
0 Likes
·
0 Votes
·
0 Comments
·
Hi,

Thanks for the sample. Seems the problem is WriteTimeout property. Try to set a value of zero in client component and try again


wsClient.WriteTimeout := 0;


Kind regards,
Sergio
·
3 years ago
·
0 Likes
·
0 Votes
·
0 Comments
·
Hi,

Thanks for the sample. Seems the problem is WriteTimeout property. Try to set a value of zero in client component and try again


wsClient.WriteTimeout := 0;


Kind regards,
Sergio
Thank you. Is this a bug or does the timeout property not work on android?
·
3 years ago
·
0 Likes
·
0 Votes
·
0 Comments
·
Hello,

Yes, it's a bug in my side because this doesn't work on Android. I've fixed for next versions. Thanks for your comments.

Kind regards,
Sergio
·
3 years ago
·
0 Likes
·
0 Votes
·
0 Comments
·
Hello,

Yes, it's a bug in my side because this doesn't work on Android. I've fixed for next versions. Thanks for your comments.

Kind regards,
Sergio
Thank you. I'll try the beta
·
3 years ago
·
0 Likes
·
0 Votes
·
0 Comments
·
View Full Post