• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
CFSocket
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

CFSocket


  • Subject: CFSocket
  • From: "sunil prajapati" <email@hidden>
  • Date: Wed, 24 Oct 2007 20:01:31 +0530

Hi Guys,

I have written client and server application in Carbon using CFSocketCreateWithNative.
I m able to control multiple clients from my server.
Now I m facing the problem when any client get disconnected from my server,I unable to identify which client has disconnected.
My server side code is as follows:


struct CLIENTCONNETED
 {

    CFSocketRef CFChildSocket;

 
 }clientconnected[100];

    struct sockaddr_in tcpip_sa;
    tcpip_socket=socket(AF_INET,SOCK_STREAM,0);
    if (tcpip_socket<0)
    {
        printf("Error: Opening Socket\n");
    }
   
    tcpip_sa.sin_len = sizeof(struct sockaddr_in);
    tcpip_sa.sin_family = AF_INET;
    tcpip_sa.sin_addr.s_addr = htonl(INADDR_ANY);
    tcpip_sa.sin_port = htons(DataSet.TCPportNum);
    memset(tcpip_sa.sin_zero,0,sizeof(tcpip_sa.sin_zero));
   
    bind(tcpip_socket, (struct sockaddr *) &tcpip_sa,sizeof(tcpip_sa));
    if(bind <0)
    {
        printf("Error:Binding Sockets.\n");
    }         
    
     
    listen(tcpip_socket,50);
 
   
    CFSocketRef   socket = CFSocketCreateWithNative(NULL,
                                                (CFSocketNativeHandle )tcpip_socket,
                                                kCFSocketAcceptCallBack,
                                                acceptConnection,
                                                NULL);



    CFRunLoopSourceRef source = CFSocketCreateRunLoopSource(NULL, socket, 0);
    CFRunLoopRef loop = CFRunLoopGetCurrent();
    CFRunLoopAddSource(loop, source, kCFRunLoopDefaultMode);
    CFRunLoopRun();
    CFRelease(source);
   




void acceptConnection(CFSocketRef socket, CFSocketCallBackType type, CFDataRef address, const void *data, void *info)
{

    CFSocketContext context;
    int *clientnum;
    clientnum=calloc(1,sizeof(int));
    *clientnum=gcount;
    memset(&context, 0, sizeof(context));
    context.info = clientnum;
    clientconnected[gcount].CFChildSocket = CFSocketCreateWithNative(NULL,
                                                 *(CFSocketNativeHandle *)data,
                                                 kCFSocketDataCallBack ,
                                                 receiveData,
                                                 &context);

    CFRunLoopSourceRef childSource = CFSocketCreateRunLoopSource(NULL, clientconnected[gcount].CFChildSocket, 0);
    CFRunLoopRef loop = CFRunLoopGetCurrent();
    CFRunLoopAddSource(loop, childSource, kCFRunLoopDefaultMode);
    CFRelease(childSource);
}



void receiveData(CFSocketRef child, CFSocketCallBackType type, CFDataRef address, const void *data, void *info)
{
    CFDataRef       newData;
    newData = (CFDataRef * )data;
    if ( CFDataGetLength(newData) == 0 )
    {
        printf("receive data is null\n");
     }

   else
   {
      printf("Data received\n");
   }

}


Please help me how to identify which client has been disconnected from my server?

Any helpful link or sample code very much helpful for me.


Thanks,
Sunil.
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: CFSocket
      • From: Quinn <email@hidden>
  • Prev by Date: Re: MoreSCF 1.1 and Cross-Development
  • Next by Date: Re: CFSocket
  • Previous by thread: Re: launchd and UNIX Domain Sockets Example
  • Next by thread: Re: CFSocket
  • Index(es):
    • Date
    • Thread