socket_create(): Unable to create socket [10047]: An address incompatible with the requested protocol was used
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.
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
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/
Could you share your changes? Maybe I can include them in the next version.
This is my problem and I could not fix any action I had to do and I had to use the old versions

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?
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
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.
Hello! @MasumNishat solution works. Could you add it in the new version?
@MasumNishat If you create a pull-request I'm happy to merge these changes into a new release.