Thanks for response.
For some reasons i've write my own code for clients.
class newWebsocket{
private var connection: NWConnection?
private var additionalHeaders: [(String, String)]
private let delegate : ServersListUpdateDelegate
init(delegate : ServersListUpdateDelegate){
self.delegate = delegate
if(Constants.shared.isStageEnvironment && AuthenticationManager.authToken != nil){
print("Authvalue is : \(AuthenticationManager.authToken!)")
additionalHeaders = [
("Authorization", AuthenticationManager.authToken!)
]
}
else{
additionalHeaders = [
("key", Constants.shared.authKey)
]
}
}
func connect() {
let url = URL(string: Constants.shared.socketUrl)!
let endpoint = NWEndpoint.url(url)
let params = NWParameters.tcp
let stack = params.defaultProtocolStack
let ws = NWProtocolWebSocket.Options(.version13)
stack.applicationProtocols.insert(ws, at: 0)
// Create the WebSocket connection
connection = NWConnection(to: endpoint, using: params)
// Set up the state change handler
connection?.stateUpdateHandler = { [weak self] newState in
switch newState {
case .ready:
print("🚧WebSocket connection established.")
// Start receiving messages when the connection is ready
self?.receiveMessage()
case .waiting(let error):
print("🚧WebSocket connection is waiting: \(error)")
case .failed(let error):
print("🚧WebSocket connection failed: \(error)")
case .cancelled:
print("🚧WebSocket connection cancelled")
default:
break
}
}
// Start the connection
connection?.start(queue: .main)
}
private func receiveMessage() {
connection?.receiveMessage { (data, context, isComplete, error) in
if let error = error {
print("Failed to receive message: \(error)")
return
}
if let data = data, let message = String(data: data, encoding: .utf8) {
print("Received message: \(message)")
// Process the received message as needed
}
// Continue to receive messages recursively
self.receiveMessage()
}
}
func reset(){}
func disconnect() {
connection?.cancel()
}
}
And i've get in any case error
🚧WebSocket connection is waiting: POSIXErrorCode(rawValue: 53): Software caused connection abort
also i've trying to remove from server side, and client side Auth headers, but it not helped