Multiple GCDAsyncSocket connections won't accept data from multiple sockets

I am trying to write an application that connects to multiple sockets at the same time, I am having problems getting data from the old socket when connecting a new one.

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

This is my general 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 for storing sockets

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

      

Note I have verified that both sockets are still connected to different IPs with the code below.

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

      

+3


source to share





All Articles