swifter icon indicating copy to clipboard operation
swifter copied to clipboard

implementing with IPv6

Open abdulstrategy opened this issue 5 years ago • 0 comments

I tried Swifter web socket

let server = HttpServer()
server["/websocket-echo"] = websocket(text: { session, text in
  print("text: \(text)")
  session.writeText(text)
})
try server.start(8081, forceIPv4: false, priority: .default)

since server.listenAddressIPv4 or server.listenAddressIPv4 does give nil always, I manually find ip and made url wsurl = "ws://\(String(describing: getMyIP()):8081)/websocket" So first issue is server.listenAddressIPv4 and server.listenAddressIPv6 always gives nil and also server.isIPv4() always return false, even everything worked well with IPv4 I am able to connect above with

let urlSession = URLSession(configuration: .default)
let webSocketTask = urlSession.webSocketTask(with: (URL(string: String(describing: wsurl)) ?? nil)!)
webSocketTask.resume()

and also able to send message with

let message = URLSessionWebSocketTask.Message.string("Hello Web-Socket")
webSocketTask.send(message) { error in
    if let error = error {
        print("WebSocket sending error: \(error)")
    }
}

I am getting output:- text: Hello Web-Socket everything is fine when the phone is connected to wifi modem, but when phone is connected to mobile network, I am getting IPv6 address. so changed wsurl = "ws://[\(String(describing: getMyIP())]:8081)/websocket" accordingly. try server.start doesn't fire any error, so hoping server started fine.

not sure websocket connected with URLSession, but can't send message. I am getting no error. so my second and crucial issue is can't send message with IPv6

please point me where I gone wrong someone please help me to solve the implementation with IPv6

abdulstrategy avatar Sep 21 '20 06:09 abdulstrategy