问题
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