• 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
Re: Socket and big data
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Socket and big data


  • Subject: Re: Socket and big data
  • From: Santino <email@hidden>
  • Date: Mon, 21 Feb 2005 13:22:59 +0100

Title: Re: Socket and big data
Hello,
I think you need a protocol to exchange messages:
Client:
        Send 4 bytes (data length) + data
Server:
        Read 4 bytes
        Convert these bytes to long (len)
        Read len bytes
        process data
        Send 4 bytes (data length) + data
Client: Read 4 bytes
        Convert these bytes to long (len)
        Read len bytes
        process data
        Send 4 bytes (data length) + data
Server:
        Read 4 bytes
        Convert these bytes to long (len)
        Read len bytes
        process data
        close connection

You must accumulate data received because tcp stack/applications  can send data in chunks so you can receive partial data in a read.

Santino

At 3:07 +0100 21-02-2005, Peter Molnár wrote:
Ahoj,

I'm trying to make a simple communication between server and client. I want to make following: the client connect to the server, send a command, server receive it, process  a received command and return processed command reply to the client.
I have a problem to receive any data bigger like an socket buffer(?) size(32kB).
On the server I send a reply with:

OSStatus err = CFSocketSendData(s, NULL, (CFDataRef)commandData, 0.0);

where the commandData are succesfully created.

On the client side I'm using for connecting to server:

- (OSStatus) connectToServer{
        CFSocketContext context = {0, fs, NULL, NULL, NULL};  // fs is pointer to my object (self)
        socket = CFSocketCreate(
                                        kCFAllocatorDefault,
                                        PF_INET,
                                        SOCK_STREAM,
                                        IPPROTO_TCP,
                                        kCFSocketDataCallBack,
                                        receive,
                                        &context);
       
        struct sockaddr_in addr;
        addr.sin_family = AF_INET;
        addr.sin_addr.s_addr = inet_addr([ server cString ]);
        addr.sin_port = port;

        CFDataRef addressData = CFDataCreate( kCFAllocatorDefault, (UInt8 *)&addr, sizeof( struct sockaddr_in ) );

        CFTimeInterval interval = 0;
        err = CFSocketConnectToAddress(
                                socket,
                                addressData,
                                interval);
                               
        if( err == 0 )
        {
                CFRunLoopRef refRunLoop = [[ NSRunLoop currentRunLoop ] getCFRunLoop ];
                CFRunLoopSourceRef sourceRunLoop = CFSocketCreateRunLoopSource(
                                                                                                kCFAllocatorDefault,
                                                                                                socket,
                                                                                                0);
                CFRunLoopAddSource(
                                refRunLoop,
                                sourceRunLoop,
                                kCFRunLoopCommonModes);
                return 0;
        }
        return err;
}

and for a receive:

void receive( CFSocketRef s, CFSocketCallBackType callbackType, CFDataRef address, const void *data, void *info )
{
        NSDictionary *userInfo = [ NSMutableDictionary dictionaryWithObject:command forKey:@"Command" ];
        NSNotification *aNotification = [ NSNotification notificationWithName:@"CommandReceived" object:(FolderSync *)info userInfo:userInfo ];
        [[ NSNotificationCenter defaultCenter ] postNotification:aNotification ];
}

The problem is that receive() function receive just a 32kB and the next datas are received in the next loop. I'm don't know how to receive a full
data(can be 120MB) in a one notification(callback). I'm thought that const void *data should store a pointer with the full data replied.

Please, help me. Should I use kCFSocketReadCallBack(and how?) instead of kCFSockedDataCallback? How can I determine(on the client side) that data was fully received(not just a 32kB part)?
Mac is great but this make me crazy. Thanks a lot.

Peter Molnar

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

This email sent to email@hidden

 _______________________________________________
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

References: 
 >Socket and big data (From: Peter Molnár <email@hidden>)

  • Prev by Date: Socket and big data
  • Next by Date: Regarding XML-RPC
  • Previous by thread: Socket and big data
  • Next by thread: Regarding XML-RPC
  • Index(es):
    • Date
    • Thread