Closed satishbabariya closed 6 years ago
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!"]) }
code
var manager: SocketManager! var socket: SocketIOClient!