Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

socket_create(): Unable to create socket [10047]: An address incompatible with the requested protocol was used #27

Open
suyovj opened this issue Jan 21, 2021 · 9 comments

Comments

@suyovj
Copy link

suyovj commented Jan 21, 2021

Hey,

I am trying to replicate the example given in Readme.

But I am stuck up with this error.

Type: ErrorException
Message: socket_create(): Unable to create socket [10047]: An address incompatible with the requested protocol was used

I haven't changed anything in the library.

Using PHP 8.0.1
OS: Windows 10

Help is appreciated.

@nekudo
Copy link
Collaborator

nekudo commented Jan 21, 2021

Hello,

I do not use any windows machines so I can not test this but it seems to be a problem with your hosts configuration. Please see: https://stackoverflow.com/questions/2370388/socketexception-address-incompatible-with-requested-protocol

@suyovj
Copy link
Author

suyovj commented Jan 23, 2021

Just found out that SOCK_DGRAM is not supported in Windows. The code has to be modified to enable support for windows.

Reference: https://devblogs.microsoft.com/commandline/af_unix-comes-to-windows/

@nekudo
Copy link
Collaborator

nekudo commented Jan 24, 2021

Could you share your changes? Maybe I can include them in the next version.

@sirj3x
Copy link

sirj3x commented Jan 27, 2021

This is my problem and I could not fix any action I had to do and I had to use the old versions

Screenshot (450)

@nekudo
Copy link
Collaborator

nekudo commented Jan 27, 2021

Can you please try to change
$this->icpSocket = socket_create(AF_UNIX, SOCK_DGRAM, 0);
to
$this->icpSocket = socket_create(AF_UNIX, SOCK_STREAM, 0);

and check if that works on a windows machine?

@cochmedia
Copy link

Can you please try to change
$this->icpSocket = socket_create(AF_UNIX, SOCK_DGRAM, 0);
to
$this->icpSocket = socket_create(AF_UNIX, SOCK_STREAM, 0);

and check if that works on a windows machine?

No

@MasumNishat
Copy link

Hello,

By changing a couple of lines I solved it.
in Server.php

private string $host;
private int $port;

then,

$this->host = $host;
    $this->port = $port;

then,

if (substr(php_uname(), 0, 7) == "Windows"){
        $this->icpSocket = socket_create(AF_INET, SOCK_DGRAM, 0);
        $ipcSocketPath = $this->host;
    } else {
        if (file_exists($ipcSocketPath)) {
            unlink($ipcSocketPath);
        }
        $this->icpSocket = socket_create(AF_UNIX, SOCK_DGRAM, 0);
    }

then,

if (substr(php_uname(), 0, 7) == "Windows") {
        $from = '';
        $port = 0;
        $bytesReceived = socket_recvfrom($this->icpSocket, $buffer, 65536, 0, $from, $port);
    } else {
        $bytesReceived = socket_recvfrom($this->icpSocket, $buffer, 65536, 0, $this->ipcSocketPath);
    }

in Application.php, removed final at line 19

Thanks a lot.

@PPhucker
Copy link

PPhucker commented Sep 7, 2021

Hello! @MasumNishat solution works. Could you add it in the new version?

@nekudo
Copy link
Collaborator

nekudo commented Sep 15, 2021

@MasumNishat If you create a pull-request I'm happy to merge these changes into a new release.

nekudo added a commit that referenced this issue Mar 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants