Reputation: 11
I'm getting my sea legs and need some pointers and a small sample of code that connects to an epp server. The sample of code need to login and send one command and receive a response.(in XML). Code can be in php or python.
This I believe will form a basis/kickstart for me to delve in further and learn more about this topic. It's driving me up the wall - in a good way as I want to solve it in one day or a thousand.
And I have been searching for days now but can't seem to make sense of the info found, and now opted to ask here for guidance.
Thank you in advance.
Upvotes: 1
Views: 2402
Reputation: 760
This is sample php script
<?php
class Epp
{
var $socket;
public function __construct()
{
}
private $_connected = false;
function connect($host, $port = 700, $timeout = 1, $ssl = true)
{
if ($this->_connected)
return true;
$target = sprintf('%s://%s', ($ssl === true ? 'ssl' : 'tcp'), $host);
$socket = fsockopen($target, $port, $errno, $errstr, $timeout);
if (!$socket) {
return new PEAR_Error("Error connecting to $target: $errstr (code $errno)");
} else {
$this->socket = $socket;
$this->_connected = true;
return $this->getFrame();
}
}
function getFrame()
{
if (feof($this->socket))
return new PEAR_Error("Connection appears to have closed.");
$hdr = @fread($this->socket, 4);
if (empty($hdr)) {
return new PEAR_Error("Error reading from server: $php_errormsg");
} else {
$unpacked = unpack('N', $hdr);
$answer = fread($this->socket, ($unpacked[1] - 4));
return $answer;
}
}
function sendFrame($xml)
{
return @fwrite($this->socket, pack('N', (strlen($xml) + 4)) . $xml);
}
function disconnect()
{
return @fclose($this->socket);
}
}
?>
And there are 4 functions , connect , getFrame , sendFrame , disconnect . Epp protocol works following . Firstly you must connect to server .
Send xml request to server and receive xml response from server .
And firstly you must login to server . for that you must send login xml to server .
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0
epp-1.0.xsd">
<command>
<login>
<clID><?php echo $username;?></clID>
<pw><?php echo $password;?></pw>
<options>
<version>1.0</version>
<lang>en</lang>
</options>
<svcs>
<svcExtension>
</svcExtension>
</svcs>
</login>
<clTRID>12345</clTRID>
</command>
</epp>
All request and responses is xml . And you can find xmls from this sites https://www.rfc-editor.org/rfc/rfc5732
Upvotes: 1