0

I am trying to Implement Banjour based application in ios. I implement success fully also sending and receiving data to one iphone to another iphone. After browsing the services all other device in the work. and display in to the Table.

enter image description here

Now i want to select some devices in the table view, and send data to the selected devices

enter image description here

For that i created only one socket in each device.

CFSocketContext socketCtxt = {0, self, NULL, NULL, NULL};   
    witap_socket = CFSocketCreate(kCFAllocatorDefault, PF_INET6, SOCK_STREAM, IPPROTO_TCP, kCFSocketAcceptCallBack, (CFSocketCallBack)&TCPServerAcceptCallBack, &socketCtxt);

    if (witap_socket != NULL)        
    {
        protocolFamily = PF_INET6;
    }
    else 
    {
        witap_socket = CFSocketCreate(kCFAllocatorDefault, PF_INET, SOCK_STREAM, IPPROTO_TCP, kCFSocketAcceptCallBack, (CFSocketCallBack)&TCPServerAcceptCallBack, &socketCtxt);        
        if (witap_socket != NULL)
        {
            protocolFamily = PF_INET;
        }
    }    

now i want to send data to the selected devices. for that I stored selected NSNetService(ie devices) another NSMutableArray. When used Click the send button particular Action will invoked.

-(void)SendActionFunction
{   
       for(int idx=0;idx<[selectedSer count];idx++)
    {
        NSNetService *service = [self.selectedSer objectAtIndex:idx];  
        NSLog(@"service......%@",[service name]);
        self.currentResolve = [self.selectedSer objectAtIndex:idx]; 
        [self.currentResolve setDelegate:self];     
        [self.currentResolve resolveWithTimeout:0.0];
    }
}

if i am trying to Resolve address for each device(above code). It will resolve only for first device. and getting error

  • (Error code=-72003]

one more problem if i resolved address for a device it automatically remove from Tableview.

So my doubts are:

  1. Why the selected device revoved?
  2. Now i create TCP based socket, How to add destination address to send data?
  3. Is it possible to send data from single socket to multiple destination?
Musthafa P P
  • 645
  • 3
  • 7
  • 21

2 Answers2

0

As per Apple's definition, A CFSocket is a communications channel implemented with a BSD socket.

You have established a socket connection between the devices. But for sending and receiving data, you must make use of NSStreams. Documentation can be found here

I see you are using Apple's sample code Witap as the reference.

For sending and receiving the data, use NSStreamDelegate also.

sunhsiv
  • 311
  • 1
  • 7
0

What about resolve and send datas 1 device per 1 device ? Sounds easier :D

BTW, there is a really nice socket library I used for a project :

https://github.com/robbiehanson/CocoaAsyncSocket

Lucien
  • 451
  • 4
  • 16