GCDAsyncSocket multiple connections wont accept data from multiple sockets

為{幸葍}努か 提交于 2019-12-07 16:23:39

问题


I am trying to write an app that connects to multiple sockets at the same time, i'm having trouble with receiving data from the old socket when a new one is connected.

The main thing is the delegate is not activated by the previously connected socket.

This is my overall program

var struct = [serverlist]() //Create array for sockets and serverinfo

func connect() {
    //Init socket 
    struct[item].socket = GCDAsyncSocket(delegate: self, delegateQueue: dispatch_get_main_queue())
    //Create error message
    var connectionError: NSError?
    //connect socket
    struct[item].socket!.connectToHost(struct[item].Serveraddress, onPort: struct[item].serverport, error: &connectionError)
}

func socket(socket : GCDAsyncSocket, didReadData data:NSData, withTag tag:Int32)
{
      //Do stuff like print data
}

This is my structure to store the sockets

struct serverlist 
{ 
    var Serveraddress = String(); 
    var socket = GCDAsyncSocket?(); 
}

NOTE I have checked that both sockets are still connected to different ip addresses with the code below.

println(Liststucture[x].socket?.isDisconnected) 
println(Liststucture[x].socket?.connectedHost) 

来源:https://stackoverflow.com/questions/29934544/gcdasyncsocket-multiple-connections-wont-accept-data-from-multiple-sockets

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!