PHP -> DM Communication Function

This is a function to make PHP communicate with DM, courtesy of Mobius Evalon and Crispy!

function export($addr,$port,$str)
{
    if($str{0} != "?") $str = ("?" . $str);
    $query = "\x00\x83" . pack("n",strlen($str)+6) . "\x00\x00\x00\x00\x00" . $str . "\x00";
    $server = socket_create(AF_INET,SOCK_STREAM,SOL_TCP) or exit('Unable to create export socket; ' . socket_strerror(socket_last_error()));
    socket_connect($server,$addr,$port) or exit('Unable to establish socket connection; ' . socket_strerror(socket_last_error()));
    $bytessent = 0;
    while($bytessent < strlen($query))
    {
        $result = socket_write($server,substr($query,$bytessent),strlen($query)-$bytessent);
        if($result === FALSE) exit('Unable to transfer requested data; ' . socket_strerror(socket_last_error()));
        $bytessent += $result;
    }
    socket_close($server);
}


And for an example:

export("127.0.0.1",1766,"dothisaction");


This will send 127.0.0.1:1766 a message saying "dothisaction," which it will receive via world/Topic.

Posted by Audeuro (Guildmaster) on Friday, July 27, 2007 10:44PM - 0 comments / Members say: yea +0, nay -0

« PHP Guild · PHP -> PHP Communication Function »

Login to post a comment.

PHP

Joined: Jul 27, 07

Blog Calendar

July 2007
Su Mo Tu We Th Fr Sa
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        
 
  Dec»