felixms / arma-rcon-class-php

A lightweight client for sending commands easily to a BattlEye server.
MIT License
46 stars 22 forks source link

No response after x seconds #16

Closed stevenklar closed 8 years ago

stevenklar commented 8 years ago

Hello Nizarii,

actually i'm using your Rcon Class in a queue daemon where I only opens the connection once and everytime I need new information there will be a new command issued.

The first command gives me successful information back. But all others after that are give me an "" empty response.

I thought maybe the heartbeat is wrong implemented. As it only get called once at the start. My understanding of a heartbeat is that you call it every x seconds to tell the server i'm still here.

Do you had this issue? I want to keep connection alive and not reconnect every 5 seconds. You know?

Regards

stevenklar commented 8 years ago

Ah. Found this one. https://www.battleye.com/downloads/BERConProtocol.txt

felixms commented 8 years ago

An empty 2-byte command packet (without actual command string) has to be sent every 45 seconds (or less) to keep the connection/login alive, if there are no other command packets being sent. If there are no command packets coming from the client for more than 45 seconds, it will be removed from BE RCon's list of authenticated clients and will no longer be able to issue any commands.

I never had this issue. I'll make the method sendHearbeat() public, so you can call it in your daemon loop in order to keep the connection alive.

stevenklar commented 8 years ago

Wait. It doesn't seem to work that way. Actually my workaround is asking for information and if the response is '' I reconnect. But this is very server intense I guess.

Even if I send heartbeat every 5 seconds there is a result drop.

felixms commented 8 years ago

I'll check the connection/socket. Maybe the timeout thing doesn't work right.

felixms commented 8 years ago

Alright, as I understand it, the client has to respond in 10 seconds to every message sent by the server . Since PHP isn't the best language for daemons and socket.io like "socket.on(...)", a solution might be calling a method every 10 seconds, which checks for unresponded messages. This way the connection won't be closed by the server.

stevenklar commented 8 years ago

Yep. That would be a solution. Do you have an idea how to do check for unresponded messages?

felixms commented 8 years ago

Roughly, I'll test if just checking the socket for a packet is a smart idea ;)

felixms commented 8 years ago

I did a lot of tests and came to the result, that it is not smart to respond to every message sent from the server. Because the in-game chat, as well as other things, are sent to all connected clients, you have to respond to all messages. This wouldn't be a problem, but we are using PHP, so you don't know how many messages are sent to the client. So instead of checking multiple times for a message, which is server intense, it's better to just reconnect. In a future update, you will also get an exception if the connection timed out (due to not responding to server messages).