Skip to content
This repository has been archived by the owner on Jan 10, 2022. It is now read-only.

Possibility to set context for SocketClient #31

Closed
wants to merge 2 commits into from

Conversation

iivannov
Copy link
Contributor

When opening a socket connection with stream_socket_client there is no possibility to add the last parameter $context.

I extended the Options class with an additional variable to accept those context options. When creating a new SocketClient instance those options are passed as a second parameter and if set are used to create new socket context with stream_context_create .

Possible usage: setting options for ssl verification

$options->setContextOptions(['ssl' => ['verify_peer' => false,'verify_peer_name' => false]]);

iivannov and others added 2 commits October 14, 2015 15:40
Updating the Options class to handle an additional $contextOptions
variable, which will be used to create a stream context to be passed as
6th parameter in stream_context_create() in SocketClient
@Irker
Copy link

Irker commented May 19, 2016

@fabiang can you look on this pull-request, please? It's very useful for devel env.

@@ -91,7 +101,8 @@ public function connect($timeout = 30, $persistent = false)
// call stream_socket_client with custom error handler enabled
$handler = new ErrorHandler(
function ($address, $timeout, $flags) {
return stream_socket_client($address, $errno, $errstr, $timeout, $flags);
$context = (null != $this->options) ? stream_context_create($this->options) : null;
return stream_socket_client($address, $errno, $errstr, $timeout, $flags, $context);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be inside an if-statement like this:

    if (null === $context) {
        return stream_socket_client($address, $errno, $errstr, $timeout, $flags);
    }
    return stream_socket_client($address, $errno, $errstr, $timeout, $flags, $context);

@fabiang
Copy link
Owner

fabiang commented May 23, 2017

Merged into develop locally. Thanks for your work!

@fabiang fabiang closed this May 23, 2017
@abdelhafiddahhani
Copy link

it doesn't work for me the connection

$options = new Options("tcp://192.168.110.20:5222");
$options->setUsername("admin@localhost")->setPassword("admin");
$client = new Client($options);
$client->connect();
error message :

message":"Stream Error: "host-""unknown"","class":"Fabiang\Xmpp\Exception\Stream\StreamErrorException","trace":[{"namespace":"","short_class":"","class":"","type":"","function":"","file":"C:\xampp\htdocs\API\vendor\fabiang\xmpp\src\Exception\Stream\StreamErrorException.php","line":77,"args":[]},""

@abdelhafiddahhani
Copy link

or got this error

{"error":{"code":500,"message":"Internal Server Error","exception":[{"message":"stream_socket_client(): Failed to enable crypto","class":"Fabiang\Xmpp\Exception\ErrorException"

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants