Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

jimgeldermann

macrumors newbie
Original poster
Sep 10, 2010
1
0
Not surprisingly I'm a bit confused. I'm using AsyncSocket to manage my connection and using their echo server to bounce messages.

When I place a char on the network:
Code:
char i = 0;
i =  64;
[dataToSend appendData:[NSMutableData dataWithBytes:&i length:sizeof(char)]];

When I decompose the message from the send function I get 64 as the value

Code:
NSData *tstData = [NSData dataWithBytes:&i length:sizeof(char)];
	unsigned char byteBuffer[sizeof(char)];
	[tstData getBytes:byteBuffer];
	NSLog(@"Output: %d", byteBuffer[0]);

But when I receive the message and move the input stream to NSMutableData and decompose it (byteBuffer is the stream as NSMutableData)

Code:
NSData *tstData = [NSData dataWithBytes:[byteBuffer subdataWithRange:NSMakeRange(0, [byteBuffer length])] length:[byteBuffer length]];
	
	unsigned char myBytes[[tstData length]];
	[tstData getBytes:myBytes];
	
	for(int i = 0; i <[tstData length]; i++){
		NSLog( @"\n\t pos: %d myBytes size %d value %d",i, [tstData length], myBytes[i]);
	}

I always get 104 as the first byte, where I am expecting the value of i from the send function.

Thanks
 

chown33

Moderator
Staff member
Aug 9, 2009
10,750
8,422
A sea of green
Post compilable code. It should be complete yet minimal. The purpose is for someone else to replicate the problem, and analyze it with minimal extraneous code.

Don't post the EchoServer, but do post the URL where you obtained it.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.