I am doing socket programming in MAC OS in which i am able to open socket but during sending a request to server am getting Type cat problems which is mention below :
If we have some value in NSString given below :
NSString *Message=@"abc";
when i am converting it into NSData or NSMutableData like :
NSData *data = [[NSData alloc] initWithData:[Msg dataUsingEncoding:NSASCIIStringEncoding]];
Here Message is converted into NSData now if i want to read this NSData into String i can read as below :
NSString *myString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
Now the problem is that i have value=2 and value=300 which represent the data type and type of request to server (While we are sending request to server). I have to convert value=2 in a byte and it should not exceed 1 Byte size. so i took data type Byte as given below :
Byte value = 2;
Now i need to know how to convert Byte into NSData without converting into NSString and then NSData (otherwise 2 is consider as a string and byte conversion may differ) and
I have convert another value=300 in a byte and it should not exceed 2 Byte size.So i took data type short int as given below :
short int j = 300;
Now here also i need to know how to convert Byte into NSData without converting into NSString and then NSData (otherwise 300 is consider as a string and byte conversion may differ).
Actually in our server we having array where first byte representing first data type as 2 for one byte size and another value=300 for two byte size. i need to know how to convert Byte and short int into NSData and after conversion into NSData i want to convert the NSData to Byte and short int value as we can do in the NSString case as i mention above Example in the starting lines. As i have to send all these NSMutableData append with each other and also including one Nsstring to be append with NSMutableData and send to server as a request. Please help me if anyone have idea regarding this issue.
Thanks