Swift无法从Node.js获取数据

时间:2019-03-19 04:20:01

标签: node.js swift real-time

您好,当我在ios ack中使用SocketIO时总是出现问题,并且数据为空,但在Web和android应用程序中运行正常时,我遇到了问题,我提供了服务器端代码和clint端此代码的工作原理?当我通过套接字发送房间ID并已实现时,套接字发出事件“ welcome”以接收数据,谢谢您的帮助

  

2019-03-16 07:41:00.447911 + 0200 ALILON Z [21158:307613]日志   SocketIOClient {/}:处理事件:带有数据的Pong:[]

     

2019-03-16 07:41:00.448000 + 0200 ALILON Z [21158:307701]日志   SocketEnginePolling:执行轮询GET   http://realapi.imatcheg.com/socket.io/?transport=polling&b64=1&sid=Us1opxksMNjHH6bpAAAB

     

2019-03-16 07:41:00.448373 + 0200 ALILON Z [21158:307701]日志   SocketEnginePolling:创建的POST字符串:19:42 [“ joinRoom”,“ 21”]

     

2019-03-16 07:41:00.448705 + 0200 ALILON Z [21158:307701]日志   SocketEnginePolling:发布

     

2019-03-16 07:41:00.448877 + 0200 ALILON Z [21158:307701]日志   SocketEnginePolling:执行轮询POST   http://realapi.imatcheg.com/socket.io/?transport=polling&b64=1&sid=Us1opxksMNjHH6bpAAAB

this is server side /=============================

socket.on("joinRoom",(room) =>{

socket.join(room);

let myJSON = [

{

name: "Banana",

points: 200,

description: "A banana grown in Ecuador."

}

]

socket.emit("welcome",myJSON);

});

socket.on("refresh",(rm)=>{

io.of("/members_chat").emit("get_history");

});

});

And this Client side /===================

let manager = SocketManager( socketURL: URL(string:"http://realapi.imatcheg.com/members_chat")!, config: [.log(true), .forcePolling(true)])

override init() {

super.init()

}

func establishConnection(){

manager.connect()

}

func closeConnection(){

manager.disconnect()

}

func joinTheRoom( room_id : String){

print(room_id)

manager.defaultSocket.emit("joinRoom", room_id )

}

func welcome ( room_id : String){

self.manager.defaultSocket.on("welcome") { (sd, ack) in

print(sd)

print("(ack)")

}

manager.defaultSocket.on(clientEvent: .connect) {data, ack in

print("socket connected")

self.joinTheRoom(room_id : room_id )

}

}

0 个答案:

没有答案