mirror of
https://github.com/apple/swift-nio
synced 2026-11-30 05:28:44 +00:00
NIOUDPEchoClient: Use connected-mode UDP
Signed-off-by: Si Beaumont <beaumont@apple.com>
This commit is contained in:
1 parent
7288536d4d
commit
ca95ec1a72
1 file changed
+16
-7
@@ -126,14 +126,23 @@ defer {
|
||||
try! group.syncShutdownGracefully()
|
||||
}
|
||||
|
||||
let channel = try { () -> Channel in
|
||||
switch connectTarget {
|
||||
case .ip(let host, _, let listeningPort):
|
||||
return try bootstrap.bind(host: host, port: listeningPort).wait()
|
||||
case .unixDomainSocket(_, let listeningPath):
|
||||
return try bootstrap.bind(unixDomainSocketPath: listeningPath).wait()
|
||||
|
||||
let channel: Channel
|
||||
let connectedMode = true
|
||||
switch connectTarget {
|
||||
case .ip(let host, let sendPort, let listeningPort):
|
||||
channel = try bootstrap.bind(host: host, port: listeningPort).wait()
|
||||
if connectedMode {
|
||||
print("Using connected-mode UDP")
|
||||
try channel.connect(to: .init(ipAddress: host, port: sendPort)).wait()
|
||||
}
|
||||
}()
|
||||
case .unixDomainSocket(let sendPath, let listeningPath):
|
||||
channel = try bootstrap.bind(unixDomainSocketPath: listeningPath).wait()
|
||||
if connectedMode {
|
||||
print("Using connected-mode UDP")
|
||||
try channel.connect(to: .init(unixDomainSocketPath: sendPath)).wait()
|
||||
}
|
||||
}
|
||||
|
||||
// Will be closed after we echo-ed back to the server.
|
||||
try channel.closeFuture.wait()
|
||||
|
||||
Reference in new issue
Block a user