Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Raspberry Pi / Sending data to an Android client app that was force closed crashes host app on RPi

Author
Message
Cybermind
Valued Member
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 15th Apr 2017 16:46 Edited at: 17th Apr 2017 10:22
Hello I have a host app on a RPi2. I check for disconnected clients, and I am sending small packets to connected Android devices. If I force close an Android app and then try to send data to that device, the host app on RPi just closes, and I have to send these packets in order to detect disconnected clients :-( And it takes a few moments for the RPi app to see that the client has been disconnected. Also, If I connect the Android app again before RPi app has detected the client as disconnected, it also closes.

Here is some code for the RPi:


And here is somet code for the Android device:
13/0
Cybermind
Valued Member
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 17th Apr 2017 16:39
To clarify:

-I have to send some form of data to a client app before the host app can detect whether or not the client app is still connected.
-If the client app on Android was force closed, sending data to that device will result in the host app on RPi closing without any error message. BUT, I have to send data before the host app can detect that the client is no longer connected.
-If I don't send data, I have to wait a little while before the client is disconnected on the host. But I have no possible way of knowing if the client was force closed and I will most likely send data to it, which results in the host app just closing without any error message.
-And if the client app is force closed, then started again BEFORE the host app sees it as disconnected, will also result in host app just closing without any error message.
13/0
Jack
19
Years of Service
User Offline
Joined: 4th Oct 2004
Location: [Germany]
Posted: 17th Apr 2017 17:54 Edited at: 17th Apr 2017 18:00
Hm, your server code 'RPi' has some flaws.

Quote: " if client_to_check > 0
net_message_created_id = CreateNetworkMessage()
AddNetworkMessageInteger(net_message_created_id,0)
SendNetworkMessage(network_id_helper_app,0,net_message_created_id)
endif"


is outside your while loop, so

Quote: "client_to_check = GetNetworkNextClient(network_id_helper_app)
"


does not work for the network message creation part, because it can also send the message to an non, existent client. - Put it in the while loop.


I honestly have all my information about the AppGameKit network from the examples within AppGameKit itself.
Just move though the index of the network commands and look at every command. There are often examples,
at least enough examples that could show you how to create a nice network-code structure.

Check out the server template I gave in the other thread:
https://forum.thegamecreators.com/thread/218435

The crash-free client add/remove stuff was already mentioned in your previous thread.

[/url]
Cybermind
Valued Member
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 17th Apr 2017 19:03 Edited at: 17th Apr 2017 19:08
Quote: "s outside your while loop, so

Quote: "client_to_check = GetNetworkNextClient(network_id_helper_app)
""


Oh, yeah, right But I send it to "0" (zero), not "client_to_check", so I send to all connected clients (I was moving around code to see what would happen, that packet is send normally, just not in the code above). The problem is that it also sends to clients that was recently force closed, and then the host app just closes. And yes, the other code in the other thread works just fine, I can run host apps now that doesn't crash, but this specific situation does not work still.

EDIT: And for the GetNetworkClientDisconnected to work properly, I have to send packets to the clients. When the delivery of a TCP packet fails, then GetNetworkClientDisconnected can see that a client was disconnected. But the problem is that the Android app was force closed, and sending data to that client will cause the host app to close/crash. Do you see the problem?
13/0
Jack
19
Years of Service
User Offline
Joined: 4th Oct 2004
Location: [Germany]
Posted: 17th Apr 2017 22:34
Does it happen, when you use the native server-/ client example, and forcekill the client while recieving messages?

[/url]
Cybermind
Valued Member
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 18th Apr 2017 11:21
It also happens with the example you have provided in this link: https://forum.thegamecreators.com/thread/218435

I only inserted a small block of code that sends a small packet to all clients.

13/0
Jack
19
Years of Service
User Offline
Joined: 4th Oct 2004
Location: [Germany]
Posted: 18th Apr 2017 22:02
SendNetworkMessage(networkId,0,net_,message_created_id) typo?

SendNetworkMessage( networkId, clientId, NetMessage )

and while you are looping though all clients, send them each a seperate message with their own clientID.
I also have no timer involved, but this is the only difference between your system and mine. And it works here.
Please send a full server/client code so we can see what exactly causes the problem.


[/url]
Cybermind
Valued Member
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 19th Apr 2017 09:15
Quote: "SendNetworkMessage(networkId,0,net_,message_created_id) typo?"

That typo is only here, not in the code, I typed it freestyle in my post, just to give an example of what I use :-P

Quote: "and while you are looping though all clients, send them each a seperate message with their own clientID."

That will produce the exact same bug I have tried that.
13/0
Cybermind
Valued Member
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 24th Apr 2017 10:19
Should I post this as a bug?
13/0
Jack
19
Years of Service
User Offline
Joined: 4th Oct 2004
Location: [Germany]
Posted: 22nd May 2017 14:54
Yes.
I confirm it with a different setup.
I got some client apps on my raspberrie that are closing now, when another wifi client looses network connection. (Bug does not happen, if I force-close the app, nor when I plug the ethernet cable out of the server)
The host server was on windows 7 / osx by ethernet.
Also the pi's.
I use the GetNetworkMessage communication method.

Maybe you can try to run your app with chmod 755 or chmod 777.
This can solve a lot of problems.

beside of that, I am also loosing some of my clients, when I restart the server. The clients should do an auto- reconnect. I think something is crashing the pi's from the network code.

If you start your by typing sudo your/program/path/and/name you will see some nice debuging lines, straight from agk in the terminal...

So, BUG confirmed.


[/url]
Cybermind
Valued Member
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 23rd May 2017 11:31
Awesome work Jack Thank you for the info on terminal debug output I will definitely use that in the future (and this time)
13/0
Cybermind
Valued Member
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 24th May 2017 11:07
I tried starting the app from a terminal, but nothing happens when I start it, no window, message or anything. I tried setting the file to chmod 777.
13/0

Login to post a reply

Server time is: 2024-03-28 16:15:45
Your offset time is: 2024-03-28 16:15:45