Вы можете использовать приведенный ниже код на языке Swift.
import SocketIO
import Foundation
let serverURL = "YourServerURL"
class SocketOpration {
static let shared = SocketOpration(socketURL: URL(string: serverURL)!)
let socketURL: URL
var socket:SocketIOClient!
var manager:SocketManager!
init(socketURL: URL) {
self.socketURL = socketURL
self.manager = SocketManager(socketURL: self.socketURL, config: [.log(false)])
self.socket = self.manager.defaultSocket
}
func setup() {
socket.on(clientEvent: .connect) {[weak self] data, ack in
print("socket connected")
}
socket.on(clientEvent: .disconnect) {[weak self] data, ack in
print("socket disconnected")
}
// Get emit Call via On method ( emit will fire from Node )
socket.on("chat") { [weak self](data, ack) in
if data.count > 0 {
}
}
}
func chatEmail(senderName: String, email: String) {
socket.emit("chat", with: [senderName , email]])
}
}
Использование: -
SocketOpration.shared.chatEmail(senderName: "JLA", email: "asdf.swift@gmail.com")
Cheers !!