Here is the code I'm using in my ViewController:
var socket:SocketIOClient?
//To print the connection status periodically
var timer:NSTimer?
override func viewDidLoad() {
super.viewDidLoad()
self.timer = NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: #selector(self.printStatus), userInfo: nil, repeats: true)
let url = "https://test.myurl:443"
self.socket = SocketIOClient(
socketURL: NSURL(string: url)!,
options: [
.Log(true),
.ForceWebsockets(false),
.ForcePolling(true),
.Secure(true),
.Path("/my-path/socket.io"),
.ExtraHeaders(["Authorization" : "Basic encoded_authorization"])
])
self.socket!.on("error"){
data, ack in
print("Event: Error")
}
self.socket!.on("disconnect"){
data, ack in
print("Event: disconnect")
}
self.socket!.on("reconnect"){
data, ack in
print("Event: disconnect")
}
self.socket!.on("reconnectAttempt"){
data, ack in
print("Event: reconnectAttempt")
}
self.socket!.on("connect") {data, ack in
print("socket is connected")
}
self.socket?.onAny(){
any in
print("Any event: \(any)")
}
self.socket!.connect()
}
func printStatus()
{
switch self.socket!.status{
case .Connected:
print("status: connected")
case .Connecting:
print("status: connecting")
case .Disconnected:
print("status: disconnected")
case .NotConnected:
print("status: notconnected")
}
}`
And this is the console:
2016-07-28 18:56:17.757 SocketIOTest[1136:511024] LOG SocketIOClient: Adding handler for event: error
2016-07-28 18:56:17.758 SocketIOTest[1136:511024] LOG SocketIOClient: Adding handler for event: disconnect
2016-07-28 18:56:17.759 SocketIOTest[1136:511024] LOG SocketIOClient: Adding handler for event: reconnect
2016-07-28 18:56:17.759 SocketIOTest[1136:511024] LOG SocketIOClient: Adding handler for event: reconnectAttempt
2016-07-28 18:56:17.759 SocketIOTest[1136:511024] LOG SocketIOClient: Adding handler for event: connect
2016-07-28 18:56:17.759 SocketIOTest[1136:511024] LOG SocketIOClient: Adding engine
2016-07-28 18:56:17.760 SocketIOTest[1136:511024] LOG SocketEngine: Starting engine. Server: https://test.myurl:443
2016-07-28 18:56:17.760 SocketIOTest[1136:511024] LOG SocketEngine: Handshaking
2016-07-28 18:56:17.761 SocketIOTest[1136:511067] LOG SocketEnginePolling: Doing polling request
2016-07-28 18:56:18.027 SocketIOTest[1136:511070] LOG SocketEnginePolling: Got polling response
status: connecting
status: connecting
status: connecting
status: connecting
status: connecting
status: connecting
status: connecting
.....
I can't find this issue somewhere else. What can I try to get ahead with this?
I have no problem connecting using your JavaScript framework.
Thank you
In your path, add an /
That's it :)
Thank you for your quick help!
@nuclearace i have the save problem
var url = "https://test.tx/"
let manager = SocketManager(socketURL: URL(string: url )!, config: [.log(true), .compress])
let socket = manager.defaultSocket
socket.on(clientEvent: .connect) {data, ack in
print("socket connected")
}
socket.onAny{
print("got event: ($0.event) with items ($0.items)")
}
socket.connect()
var x = 0
while true {
print(socket.status)
x = x+1
print(x)
}
it stuck in connecting
how can i solve it
Most helpful comment
In your path, add an
/