How to connect Socket in Swift 4

前端 未结 3 1586
时光取名叫无心
时光取名叫无心 2021-02-06 16:26

I want to connect my app to the socket here is the code :-

  import UIKit
  import SocketIO

 class SocketIOManager: NSObject {
static let manager = SocketManage         


        
3条回答
  •  不要未来只要你来
    2021-02-06 17:28

    try this Example:

     let manager = SocketManager(socketURL: URL(string: 
     "http://xxxxxxxxx.com")!, config: [.log(true), .compress])
     var socket = manager.defaultSocket
    
    socket.connect()
        socket.on(clientEvent: .connect) {data, ack in
            print("socket connected")
            self.gotConnection()
           }
        }
    
     func gotConnection(){
    
     socket.on("new message here") { (dataArray, ack) in
    
        print(dataArray.count)
    
         }
       }
    

提交回复
热议问题