• 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: Parsing a packet Async Socket
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Parsing a packet Async Socket


  • Subject: Re: Parsing a packet Async Socket
  • From: Agent M <email@hidden>
  • Date: Sat, 4 Mar 2006 10:09:46 -0500

Hi Andrea,

The -readData... methods return NSData objects (a byte stream) so any interpretation is yours alone.

To parse the message you send asynchronously in the receiving method, you should use an accumulation buffer (of object scope) to first append the incoming data. This is because the whole message may not have arrived at the time the message was posted. Once you detect that the buffer contains a complete message, you can parse it and post the event. Once the message is handled, remove the bytes of the message from the FIFO buffer.

In your case below, you can use -bytes to get at the byte values that interest you.

Good luck!

-M

On Mar 4, 2006, at 8:44 AM, Andrea Salomoni wrote:

Hi to all,

I'm trying to use Async Sockets to parse a packet returned from a server.
My packet is divided into a packet header that contains a payload length and a command.
How can I parse it?


I have something like this:

-(void)sendKeepAlive
{
char buff[20];

buff[0] = 17;
buff[1] = 0;
buff[2] = 10;

int i;
for (i=3; i<20; i++)
{
buff[i] = 0;
}
NSMutableData * keepAliveData = [[NSMutableData alloc]init];
[keepAliveData appendBytes:buff length:20];
[self writeOnServer:keepAliveData];



}
This is an header example .... If I use [socket readDataWithTimeOut:-1 tag:1]; what kind of data is returned?
Thank you all for any kind of help
Andrea


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


This email sent to email@hidden

¬ ¬ ¬ ¬ ¬ ¬ ¬ ¬ ¬ ¬ ¬ ¬ ¬ ¬ ¬ ¬ ¬ ¬
AgentM
email@hidden
¬ ¬ ¬ ¬ ¬ ¬ ¬ ¬ ¬ ¬ ¬ ¬ ¬ ¬ ¬ ¬ ¬ ¬

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Parsing a packet Async Socket
      • From: Andrea Salomoni <email@hidden>
References: 
 >Parsing a packet Async Socket (From: Andrea Salomoni <email@hidden>)

  • Prev by Date: Re: how to debug notification that's never received?
  • Next by Date: Re: how to debug notification that's never received?
  • Previous by thread: Parsing a packet Async Socket
  • Next by thread: Re: Parsing a packet Async Socket
  • Index(es):
    • Date
    • Thread