[En-Nut-Discussion] Sending Numerical Data
Ulrich Hertlein
ulrich.hertlein at artcom.de
Thu Feb 1 10:03:02 CET 2007
You mean how to encode/send a 16-bit int? Like that?
unsigned short packetNumber = 0xbeef;
fwrite(&packetNumber, sizeof(packetNumber), 1, TCPStream);
Cheers,
/ulrich
MUHAMMAD AZEEM AZAM wrote:
> I have to send more than 128 BYtes of Data but in the form of 128 Bytes chunk.
> The first 2 Bytes show the packet number.
> in the first 2 Bytes how can i reach upto from counting packets 0-65536.
> 2power16 = 6536
> how is that possible
>
> bye
>
> "Thiago A. Corrêa" <thiago.correa at gmail.com> wrote:
> Muhammad,
>
> Yeah, it appears that you are sending in ASCII. Althought I don't
> understand your code. To use the binary value just dont enclose it with ' or
> ". Sorry I can't be of further assistance but I can't make much sense of
> what the problem is.
>
> Cheers.
>
>
> On 1/31/07, MUHAMMAD AZEEM AZAM wrote:
>> Hi
>>
>> I have to send now more than 128 Bytes of Data. (1 Packet = 128 BYtes)
>> The first two Bytes are numerical Numbers that shows tha packet.
>> The code below (Please if u can make it better then it would be helpful)
>> its working and showing numbers from 0 t0 99.
>> But i think its in ASCII Format.
>> 1) How can i send in Binary.
>> 2) Since 2-Bytes so i need nos from 0 to 65536.
>> hows that possible
>> ------------------------------------------------------
>> unsigned int packet_number_L = '0';
>> unsigned char packet_number_R = '0';
>> ---------------------------------------------------------
>> its the part of main()
>>
>> if (strncmp(buff, "packet\n", got_data) == 0) //If Match
>>
>> {
>> int p_size = 128;
>> char p_array[p_size];
>> int index = 0;
>>
>> p_array[0]= packet_number_L;
>> p_array[1]= packet_number_R;
>>
>> for(index=2;index
>> {
>> p_array[index] = rand()%26+'a';
>> }
>>
>> fwrite(p_array,sizeof(p_array),1,TCPStream);
>>
>>
>> if(packet_number_R == 57)
>> {
>> packet_number_R = '0';
>> packet_number_L++;
>> }
>> else
>> {
>> packet_number_R ++;
>> }
>>
>> if(packet_number_R == 57 && packet_number_L ==57)
>> {
>> packet_number_R = '0';
>> packet_number_L = '0';
>> }
>>
>> continue;
>> }
--
Ulrich Hertlein | Software Development
ART+COM AG
Kleiststr. 23-26 | 10787 Berlin | Germany
phone: +49.30.21001-433
fax: +49.30.21001-555
http://www.artcom.de
More information about the En-Nut-Discussion
mailing list