-
Notifications
You must be signed in to change notification settings - Fork 855
Closed
Labels
Description
I use the emit method as follows. If i remove the socket.connect() from the sendTextMessage method then emit is not triggered on the server side. If connect is called inside the method it works for sometime and then stops. sendTextMessage is triggered by button tap. Any help is appreciated.
class SocketIOManager: NSObject {
static let sharedImstance = SocketIOManager()
var socket: SocketIOClient = SocketIOClient(socketURL: NSURL(string: "http://localhost:3030")!, options: [.Log(false), .ForcePolling(true)])
override init() {
super.init()
}
func establishConnection(){
socket.connect()
socket.on("hello") { (data, ack) in
print("Hello is triggered", data);
}
sendTextMessage()
}
func closeConnection(){
socket.disconnect()
}
func sendTextMessage(){
socket.connect()
socket.emit("connectUser", "Dummy data")
}
}
In the above code connect is triggered twice and hence two sockets are connected with the server and it seems wrong to me. Please help me. Thanks.