socketio / socket.io-client-swift

Other
5.22k stars 844 forks source link

Broadcast Didn't working #284

Closed thegoal closed 8 years ago

thegoal commented 8 years ago

hi ,

I am trying to send a broadcast message from iOS swift client. I didn't write a server side code (is server side compulsory ?) . I also want to send message direct to other user (without server side interaction) is it posible too ?.

But i cant broadcast yet .. :(

i am trying like following

    self.socket = SocketIOClient(socketURL: "http://10.11.10.115:2000", options: [.Log(true), .ForcePolling(true),.ForceWebsockets(true), .ConnectParams(["ishaqShafiq":"username"])])          
    self.addHandlers()
    self.socket.connect().

    func addHandlers() {
           self.socket.on("connect") {data, ack in
               // Sending message
                let mesage = ["message":"this is message","type":"broadcast"]      
                self.socket.emitWithAck("chatMessage", mesage)(timeoutAfter: 0) {data in
                print("message sent: (data)")
           }
           self.socket.on("chatMessage") {[weak self] data, ack in
                let alert = UIAlertView(title: "Burrraaa",
                message: "You receive a message", delegate: self,
                cancelButtonTitle: "YES", otherButtonTitles: nil)
                alert.show()
    }

But i didn't receive Ack of message sending , and didn't receive too .

Any thing i am doing wrong ?

nuclearace commented 8 years ago

I didn't write a server side code

If you want to get acks from the server, you have to write it to do so.

I also want to send message direct to other user

This isn't possible with socket.io

thegoal commented 8 years ago

I don't want Ack from server , I want to send client to client , and broadcast form client too. But emit isnt working , i am not able to receive an emitted event . Following are the logs. .....

Got event: connect, with items: Optional(( )) 2016-01-22 10:09:56.517 TicTacIOiOS[822:12555] LOG SocketEngine: Writing ws: has data: 0 2016-01-22 10:09:56.518 TicTacIOiOS[822:12555] LOG SocketEngine: Sending ws: as type: 2 2016-01-22 10:09:56.604 TicTacIOiOS[822:12556] LOG SocketIOClient: Emitting: 2["chatMessage","Hi how are you buddy"] 2016-01-22 10:09:56.605 TicTacIOiOS[822:12556] LOG SocketEngine: Writing ws: 2["chatMessage","Hi how are you buddy"] has data: 0 2016-01-22 10:09:56.606 TicTacIOiOS[822:12556] LOG SocketEngine: Sending ws: 2["chatMessage","Hi how are you buddy"] as type: 4 2016-01-22 10:10:00.130 TicTacIOiOS[822:12557] LOG SocketEngine: Got message: 3

nuclearace commented 8 years ago

Well direct client to client isn't possible. And I don't think you can do direct broadcast from the client. Best you could do would be to have the server listen for an event and then have it be broadcasted by the server. Im not entirely sure about server stuff though

thegoal commented 8 years ago

Ok .Thanks @nuclearace . I am moving to this approach now.