nuclearace / Socket.IO-Client-Swift

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

Emmit dosn't work #161

Closed satishbabariya closed 6 years ago

satishbabariya commented 6 years ago

code

var manager: SocketManager! var socket: SocketIOClient!

override func viewDidLoad() {
    super.viewDidLoad()
    manager = SocketManager(socketURL: URL(string: "http://localhost:3000")!, config: [.log(false), .compress])
    socket = manager.defaultSocket

    socket.on(clientEvent: .connect) { _, _ in
        print("socket connected")
    }

    socket.on("hi") { data, _ in
        print(data)
    }

    socket.onAny { event in
        print(event.event, event.items)
    }

    socket.on(clientEvent: SocketClientEvent.error) { data, ack in
        print("error", data, ack)
    }

    socket.connect()

    // Do any additional setup after loading the view, typically from a nib.
}

@IBAction func action(_ sender: Any) {
    socket.emit("message", with: ["Hello everyone!"])

}