nuclearace / Socket.IO-Client-Swift

socket.io-client for Swift
Other
361 stars 53 forks source link

Server is no more connected after one response #113

Open ShoaibHussan1 opened 8 years ago

ShoaibHussan1 commented 8 years ago

hi every one I am using socket.io and connecting to server but is does't work i am showing socket status in timer and it keeps giving output like this

Got message: {"started":"2016-03-16T11:36:34.106Z","uptime":72233.993} Connecting Connecting Connecting LOG SocketIOClient: Handling event: error with data: ( "Tried emitting customer:settings when not connected" ) Connecting Connecting

Here is my code

override func viewDidLoad() {
        super.viewDidLoad()
        durationTimer =  NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector:       Selector("CheckSocketStatus"), userInfo: nil, repeats: true);
        socket = SocketIOClient(socketURL: "my server URL",options:[.Log(true), .ForcePolling(false)])
        socket.connect()
        self.listenSocketResponse()
    }

    func listenSocketResponse(){
        socket.on("customer:settings") {data, ack in
          print (data)
            if let response = data[0] as? Double {
            print(response)

            }
        }
    }
    func CheckSocketStatus(){
        print(socket.status)
    }
    @IBAction func socketAct(sender: AnyObject) {

        let jsonInput = ["accessToken":"B5FdJ1VvLiLIdvpz"]
        socket.emit("customer:settings", withItems: [jsonInput])
    }