我正在尝试构建一个聊天应用程序,但我知道如何在Swift中集成套接字I / O.我正在关注this tutorial。
This is my code image I am getting like this error
我怎么知道我的socketIO连接到服务器?我不确定。
import UIKit
import SocketIO
class ViewController: UIViewController {
override func viewDidLoad() {
let socket = SocketIOClient(socketURL: NSURL(string: "http://localhost:8080")!)
socket.on("connect") { _, _ in
print("socket connected")
socket.emit("ping", "data")
}
socket.on("ping") { _, _ in
print("ping received")
}
socket.connect()
}
}
答案 0 :(得分:0)
您应该使用SocketManager
(创建和管理客户端)。以下是最基本形式的示例:
let socketManager = SocketManager(socketURL: URL(string: "http://localhost:8080")!)
let socket = socketManager.defaultSocket
socket.on("connect") { _, _ in
print("socket connected")
socket.emit("ping", "data")
}
socket.on("ping") { _, _ in
print("ping received")
}
socketManager.connect()