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:
// set window properties
SetWindowTitle( "Battle Server" )
SetWindowSize( 640, 480, 0 )
// set display properties
SetVirtualResolution( 640, 480 )
SetOrientationAllowed( 1, 1, 1, 1 )
SetSyncRate(10,0)
network_id_helper_app = HostNetwork("Battle Server 1","Host",port_2)
SetNetworkLatency(network_id_helper_app,100)
do
timer_stored = GetMilliseconds()
client_to_check = GetNetworkFirstClient(network_id_helper_app)
while client_to_check > 0
If GetNetworkClientDisconnected(network_id_helper_app,client_to_check)
DeleteNetworkClient(network_id_helper_app,client_to_check)
EndIf
client_to_check = GetNetworkNextClient(network_id_helper_app)
endwhile
if helper_app_alive_packet_delay_timer < timer_stored
helper_app_alive_packet_delay_timer = timer_stored + 200
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
endif
sync()
loop
And here is somet code for the Android device:
// Project: Battle helper app
// Created: 2017-04-13
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "Battle helper app" )
SetWindowSize( 640, 480, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 10, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
AddVirtualButton(1,50,50,80)
CreateText(1,"Stefan")
SetTextSize(1,50)
SetTextPosition(1,100,20)
AddVirtualButton(2,50,150,80)
CreateText(2,"Olivur")
SetTextSize(2,50)
SetTextPosition(2,100,120)
do
if GetVirtualButtonPressed(1)
player_number = 1
exit
endif
if GetVirtualButtonPressed(2)
player_number = 2
exit
endif
sync()
loop
DeleteText(1)
DeleteText(2)
DeleteVirtualButton(1)
DeleteVirtualButton(2)
network_id = JoinNetwork("192.168.10.32",5002,"Helper app")
do
timer_stored = GetMilliseconds()
if retrieve_player_turn_timer < timer_stored
retrieve_player_turn_timer = timer_stored + 1000
if IsNetworkActive(network_id) = 0 then network_id = JoinNetwork("192.168.10.32",5002,"Helper app")
net_message_created_id = CreateNetworkMessage()
AddNetworkMessageInteger(net_message_created_id,1)
AddNetworkMessageInteger(net_message_created_id,player_number)
SendNetworkMessage(network_id,1,net_message_created_id)
endif
net_message_recieved = GetNetworkMessage(network_id)
if net_message_recieved > 0
message_type = GetNetworkMessageInteger(net_message_recieved)
if message_type = 1
turn_is_up = 1
endif
if message_type = 2
turn_is_up = 2
endif
DeleteNetworkMessage(net_message_recieved)
endif
if player_number = 1 then print("Stefan")
if player_number = 2 then print("Olivur")
if turn_is_up = 1 Then print("Your turn is up!")
if turn_is_up = 2 then print("It is NOT your turn!")
Sync()
loop
13/0