问题描述:

I am attempting to connect to a socket. I can see the connection connect and disconnect in my terminal when I launch or close my app but anytime I try to emit I get an error

SocketIOClient: Handling event: error with data: ["Tried emitting connect when not connected"]

If I am showing as connected in the terminal why is my app not recognizing the connection?

I am using Ratchet as a php socket server.

class SocketIOManager: NSObject {

var socket: SocketIOClient?

override init() {

super.init()

self.socket = SocketIOClient(socketURL: URL(string: "http://166.62.121.191:8495")!, config: [.log(true), .reconnects(true), .reconnectWait(10), .forcePolling(true), .forceWebsockets(true)])

}

static let instance = SocketIOManager()

func establishConnection() {

socket?.onAny { (event: SocketAnyEvent) -> Void in

print("Got event: \(event.event), with items: \(event.items)")

}

socket?.on("connect") { (data, ack) in

print(data)

}

socket?.connect()

}

func closeConnection() {

socket?.disconnect()

}

}

相关阅读:
Top