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

[Fix] Network 서비스에서 사용할 NWParameter 옵션 변경 #153

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions NearbyNetwork/NearbyNetwork/Sources/NearbyNetworkBrowser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,10 @@ public final class NearbyNetworkBrowser {
}
weak var delegate: NearbyNetworkBrowserDelegate?

init(serviceType: String) {
let option = NWProtocolFramer.Options(definition: NearbyNetworkProtocol.definition)
let parameter = NWParameters.tcp
parameter
.defaultProtocolStack
.applicationProtocols
.insert(option, at: 0)
init(serviceType: String, networkParameter: NWParameters) {
nwBrowser = NWBrowser(
for: .bonjourWithTXTRecord(type: serviceType, domain: nil),
using: parameter)
using: networkParameter)
self.browserQueue = DispatchQueue.global()
self.serviceType = serviceType
self.logger = Logger()
Expand Down
10 changes: 3 additions & 7 deletions NearbyNetwork/NearbyNetwork/Sources/NearbyNetworkListener.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,10 @@ public final class NearbyNetworkListener {
init(
peerID: UUID,
serviceName: String,
serviceType: String
serviceType: String,
networkParameter: NWParameters
) {
let option = NWProtocolFramer.Options(definition: NearbyNetworkProtocol.definition)
let parameter = NWParameters.tcp
parameter.defaultProtocolStack
.applicationProtocols
.insert(option, at: 0)
nwListener = try? NWListener(using: parameter)
nwListener = try? NWListener(using: networkParameter)
listenerQueue = DispatchQueue.global()
self.peerID = peerID
self.serviceName = serviceName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public final class RefactoredNearbyNetworkService {
private let serviceName: String
private let serviceType: String
private let peerID: UUID
private let nearbyNetworkParameter: NWParameters
private let nearbyNetworkListener: NearbyNetworkListener
private let nearbyNetworkBrowser: NearbyNetworkBrowser
private let nearbyNetworkServiceQueue: DispatchQueue
Expand All @@ -36,11 +37,31 @@ public final class RefactoredNearbyNetworkService {
peerID = myPeerID
nearbyNetworkServiceQueue = DispatchQueue.global()
logger = Logger()

let option = NWProtocolFramer.Options(definition: NearbyNetworkProtocol.definition)
let tcpOption = NWProtocolTCP.Options()
tcpOption.enableKeepalive = true
tcpOption.keepaliveIdle = 5
tcpOption.keepaliveCount = 2
tcpOption.keepaliveInterval = 3
tcpOption.connectionTimeout = 5
tcpOption.connectionDropTime = 5
tcpOption.persistTimeout = 5
Comment on lines +42 to +49
Copy link
Member

Choose a reason for hiding this comment

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

와우 이런 기능들을 딸깍 한번으로 가능한구요..?

나중에 기회가 된다면, 이런 option설정하는 것도 따로 뺄 수 있으면 좋겠네요!!

Copy link
Collaborator

Choose a reason for hiding this comment

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

따로 분리하는 것도 좋은 생각인 것 같습니다!!
나중에 설정이 더 복잡해지면 꼭!!!! 분리하겠습니다

nearbyNetworkParameter = NWParameters(tls: nil, tcp: tcpOption)

nearbyNetworkParameter.defaultProtocolStack
.applicationProtocols
.insert(option, at: 0)
nearbyNetworkParameter.includePeerToPeer = true

nearbyNetworkListener = NearbyNetworkListener(
peerID: peerID,
serviceName: serviceName,
serviceType: serviceType)
nearbyNetworkBrowser = NearbyNetworkBrowser(serviceType: serviceType)
serviceType: serviceType,
networkParameter: nearbyNetworkParameter)
nearbyNetworkBrowser = NearbyNetworkBrowser(
serviceType: serviceType,
networkParameter: nearbyNetworkParameter)
nearbyNetworkConnections = [:]
jsonEncoder = JSONEncoder()
jsonDecoder = JSONDecoder()
Expand Down