public function open() { $this->close(); if (false === ($socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP))) { throw new ConnectionException(sprintf('Unable to create socket: %s.', socket_strerror(socket_last_error()))); } if (false === @socket_connect($socket, $this->host, $this->port)) { throw new ConnectionException(sprintf('Unable to connect: %s.', socket_strerror(socket_last_error($socket)))); } $this->socket = $socket; $greeting = socket_read($socket, IProto::GREETING_SIZE); return IProto::parseSalt($greeting); }
public function testParseSalt() { $salt = '12345678901234567890'; $greeting = base64_encode(str_repeat('x', 48) . $salt . str_repeat('x', 100)); $this->assertSame($salt, IProto::parseSalt($greeting)); }