• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

PHP sockets

Acubens

Old Penguin
Joined
May 6, 2008
Messages
1,261
Solutions
13
Reaction score
184
Location
Venezuela
I want do a simple server list from 0 to learn a bit, but how i can get status, players and others thing from a server game (Not only tibia) i see some lib's to work with this but i dont want copy it i want understand pass by pass :> someone can explain me the basic of how the sockets work?
 
Last edited:
can explain me the basic of how the sockets work?

Why do you ask such things in otland? Do you really expect someone to waste the time and write tutorials for you? Just use google, there is plenty of information. Here is example of how to receive information from a game server (TFS):

Code:
 $info = chr(6).chr(0).chr(255).chr(255).'info';
            $sock = @fsockopen("127.0.0.1", 7171, $errno, $errstr, 1);
            if ($sock)
            {
                    // Receive data from server
                fwrite($sock, $info);
                $data = '';
                while (!feof($sock))
                {
                    $data .= fgets($sock, 1024);
                }
                fclose($sock);
                
                    // parse server status information
                preg_match('/players online="(\d+)" max="(\d+)"/', $data, $matches);
                $server['status'] = 1;
                $server['players_online'] = $matches[1];
                $server['players_max'] = $matches[2];
                
                    // uptime
                preg_match('/uptime="(\d+)"/', $data, $matches);
                $h = floor($matches[1] / 3600);
                $m = floor(($matches[1] - $h*3600) / 60);
                $server['uptime'] = $h.'h '.$m.'m';
                
                    // monsters
                preg_match('/monsters total="(\d+)"/', $data, $matches);
                $server['monsters'] = $matches[1];
                
                $server['last_check'] = time();
            }
            else
            {
                $server['status'] = 0;
                $server['players_online'] = 0;
                $server['players_max'] = 0;
                $server['uptime'] = 0;
                $server['last_check'] = time();
            }

Study, experiment and once you have more specific problems, then it's ok to ask for help.
 
Why you have to respond rudely?, i not asking anyone to write me a tutorial.

someone can explain me the basic of how the sockets work

well, not problem and thanks.
 
Back
Top