@@ -19,14 +19,13 @@ public function __construct(LoopInterface $loop, Resolver $resolver = null)
19
19
$ this ->resolver = $ resolver ;
20
20
}
21
21
22
- public function createClient ($ host , $ port )
22
+ public function createClient ($ address )
23
23
{
24
24
$ factory = $ this ;
25
25
$ loop = $ this ->loop ;
26
26
27
- return $ this ->resolve ($ host )->then (function ($ ip ) use ($ loop , $ port , $ factory ) {
28
- $ address = $ factory ->createAddress ($ ip , $ port );
29
- $ socket = stream_socket_client ('udp:// ' . $ address , $ errno , $ errstr );
27
+ return $ this ->resolve ($ address )->then (function ($ address ) use ($ loop ) {
28
+ $ socket = stream_socket_client ($ address , $ errno , $ errstr );
30
29
if (!$ socket ) {
31
30
throw new Exception ('Unable to create client socket: ' . $ errstr , $ errno );
32
31
}
@@ -35,15 +34,13 @@ public function createClient($host, $port)
35
34
});
36
35
}
37
36
38
- public function createServer ($ port , $ host = ' 127.0.0.1 ' )
37
+ public function createServer ($ address )
39
38
{
40
39
$ factory = $ this ;
41
40
$ loop = $ this ->loop ;
42
41
43
- return $ this ->resolve ($ host )->then (function ($ ip ) use ($ loop , $ port , $ factory ) {
44
- $ address = $ factory ->createAddress ($ ip , $ port );
45
-
46
- $ socket = stream_socket_server ("udp:// " . $ address , $ errno , $ errstr , STREAM_SERVER_BIND );
42
+ return $ this ->resolve ($ address )->then (function ($ address ) use ($ loop ) {
43
+ $ socket = stream_socket_server ($ address , $ errno , $ errstr , STREAM_SERVER_BIND );
47
44
if (!$ socket ) {
48
45
throw new Exception ('Unable to create server socket: ' . $ errstr , $ errno );
49
46
}
@@ -52,8 +49,12 @@ public function createServer($port, $host = '127.0.0.1')
52
49
});
53
50
}
54
51
55
- protected function resolve ($ host )
52
+ protected function resolve ($ address )
56
53
{
54
+ if (strpos ($ address , ':// ' ) === false ) {
55
+ $ address = 'udp:// ' . $ address ;
56
+ }
57
+ $ parts = parse_url ($ address );
57
58
// there's no need to resolve if the host is already given as an IP address
58
59
if (false !== filter_var ($ host , FILTER_VALIDATE_IP )) {
59
60
return When::resolve ($ host );
0 commit comments