css Wrote:The php-irc bot i'm building the module for already has some very nice socket functionalities.gertjuhh Wrote:Problem is I can't use a timeout as I'm handling an irc connection aswell.Why not?
It tells when there's any data to read and then allows me to work with it.
css Wrote:Shame really, but i gues it'll have to do for now...gertjuhh Wrote:It's not so much the socket stuff that's causing the problem, but the inability to tell when i have received all data belonging to a single rcon request reply (being build up over 1 or more packages).Hmm.. it seems you can't. None of the packets include the total length of the reply, so you'll just have to do some sort of timeout in the end. Now it starts to come back into my mind too. I remember using the same kind of "wait 0.5 seconds and assume all packets have arrived" style before doing the implementation I've got now. I guess that's the only way.
css Wrote:Whoops, sorry about that.gertjuhh Wrote:You're first reading the first 4 bytes to get the package size, after which you read the length + ANOTHER extra 4 bytes. Which would come to a total of 4 (length field) + packagesize + 4. I have never had the problem of where the first 4 bytes would not contain the actual package lengthSee the flags, I'm just peeking
The MSG_PEEK flag doesn't remove the data from the queue, so the next time I do call to recv, the first four bytes are still the size field. I don't remember exactly why I came up with this solution, but it's probably got something to do with not getting into infinite blocking read if there's no reply from the server - although that's exactly what will happenCode:
$sock->recv($buffer, 4, MSG_PEEK); # Peek size field (32b int)
I didn't read up on those flags cause I use other functions to work with sockets.
Still I've never had a packet not include the packet size.
Sometimes a packet is send over 2 'tcp replies' (make any sence??), are you taking that into account?
Before i made a fix for this I did have some 'broken' packets
raydan Wrote:i have a java rcon source code, that can connect multi servers and send many rcon commands to all server at the same time by using thread.How is this relevant to the discussion!?