3

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) 
nsij22
  • 869
  • 10
  • 20
  • Note: i have switched everything back to NSStream and have multiple connections working but would love to switch back to this framework if possible but have spent a lot of time on it already so have basically given up. – nsij22 Apr 30 '15 at 04:08

0 Answers0