Click here to Skip to main content
15,940,430 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: why cannot find code map in vistual studio2012 update2? Pin
Sarath C15-Apr-13 7:19
Sarath C15-Apr-13 7:19 
AnswerRe: why cannot find code map in vistual studio2012 update2? Pin
«_Superman_»15-Apr-13 16:16
professional«_Superman_»15-Apr-13 16:16 
Questionthe big-ending and little-ending Pin
ITboy_Lemon13-Apr-13 6:27
professionalITboy_Lemon13-Apr-13 6:27 
AnswerRe: the big-ending and little-ending Pin
dusty_dex13-Apr-13 6:57
dusty_dex13-Apr-13 6:57 
GeneralRe: the big-ending and little-ending Pin
pasztorpisti13-Apr-13 11:56
pasztorpisti13-Apr-13 11:56 
GeneralRe: the big-ending and little-ending Pin
dusty_dex13-Apr-13 12:16
dusty_dex13-Apr-13 12:16 
GeneralRe: the big-ending and little-ending Pin
pasztorpisti13-Apr-13 13:36
pasztorpisti13-Apr-13 13:36 
AnswerRe: the big-ending and little-ending Pin
pasztorpisti13-Apr-13 11:49
pasztorpisti13-Apr-13 11:49 
You don't have to use the function on the data that you are transferring.

If you don't know what endianness means then read this first: http://en.wikipedia.org/wiki/Endianness[^]

When you are filling some data structures of the socket api (like the port parameter of sockaddr_in) then you have to specify the port number in big endian as the socket api expects you to give port numbers and inet4 addresses in big endian format. The reason for this is probably that some guys decided to use big endian. (I think requiring the use of htons and its friends was a bad idea as this transormation from host to network byte order could be done by the socket api implementation itself, but thats another subject for debate...). htons() always returns the 16 bit integer in big endian format regardless of the endianness of your machine. If your machine is big endian then it does nothing, if your machine is little endian then it swaps the bytes. Anyway the htons is a acronym for HostToNetworkShort - I didn't know that for some time in the past and without that it was quite hard for me to memorize these functions: HostToNetworkShort, NetworkToHostShort (16bit), HostToNetworkLong, NetworkToHostLong (32bit). Since these days most of the user machines and a lot of server machines are little endian you have to use these functions when the socket api you are calling requires them.

When you are transferring your own data you decide what byte order to use. For example if both of your machines (server and client) are little endian then it is logical to transfer 16bit and wider integers in little endian. However if the endianness of the machines are different then you have to choose whether you use little or big endian format in your data stream. If you choose little endian, then you have to do nothing on the little endian when you are sending/receiving network data, but you have to swap byte order on the big endian machine.

Since you called this whole stuff "the big-ending and little-ending" I assume you know not too much about endianness and I try to give you some help here. The two most important parts of the computer from the programmer's perspective are the processor and the memory. Imagine the memory as a big byte array. (pointers are basically just indexes into this byte array! Smile | :) What the computer does is basically the following: It reads instructions from the memory and executes them. During instruction execution the processor loads values from the memory into its own internal storages ("variables"/registers http://en.wikipedia.org/wiki/Processor_register[^]) and then performs calculations with these loaded values and later the processor stores these values back to memory. The difference between big-endian and little endian processors is the way they load/store integers that consist of more than 1 byte. Lets demonstrate that with and example: lets say you have a 16 bit integer in memory (2 bytes in hexadecimal):
01 00
If you load these 2 bytes on a little endian machine then the processor will load it as 0x0001, but a big endian will load these 2 bytes as 0x0100.
The same is true not only for data loading from memory but also for storing. Lets say you make complex calculations and the result is a 16 bit number that you want to store somewhere in memory. If the result of the calculation is 1 then a little endian processor stores 01 00 into the memory while the big endian stores 00 01.
TCP does nothing with the order of bytes when you transfer them over the wire. However if the endianness of the 2 machines (connected by TCP) differes then you have to take care.
Lets say you connect a little endian windows machine with a big endian linux machine using TCP. You calculate this, calculate that on your windows machine and lets say the result of the calculation is 1. You store this to memory on your little endian windows machine (01 00) and send it with TCP to the linux machine. If you load it on the big endian machine without byte swap then the big endian machine will see 0x0100 and not 0x0001. You can decide to use big endian in your transferrable data but in that case you have to convert on the windows machine (instead of the linux) every time you load or send network data.
GeneralRe: the big-ending and little-ending Pin
ITboy_Lemon13-Apr-13 14:41
professionalITboy_Lemon13-Apr-13 14:41 
GeneralRe: the big-ending and little-ending Pin
pasztorpisti14-Apr-13 8:29
pasztorpisti14-Apr-13 8:29 
AnswerRe: the big-ending and little-ending Pin
Erudite_Eric13-Apr-13 23:37
Erudite_Eric13-Apr-13 23:37 
AnswerRe: the big-ending and little-ending Pin
jschell14-Apr-13 7:08
jschell14-Apr-13 7:08 
AnswerRe: the big-ending and little-ending Pin
Sarath C15-Apr-13 7:09
Sarath C15-Apr-13 7:09 
QuestionHandling Cdialog's in a App. Pin
Donguy197612-Apr-13 16:50
Donguy197612-Apr-13 16:50 
AnswerRe: Handling Cdialog's in a App. Pin
Richard MacCutchan12-Apr-13 22:07
mveRichard MacCutchan12-Apr-13 22:07 
SuggestionRe: Handling Cdialog's in a App. Pin
David Crow13-Apr-13 15:30
David Crow13-Apr-13 15:30 
GeneralRe: Handling Cdialog's in a App. Pin
H.Brydon15-Apr-13 18:02
professionalH.Brydon15-Apr-13 18:02 
QuestionOutlook MSG files Pin
Joe Woodbury12-Apr-13 7:26
professionalJoe Woodbury12-Apr-13 7:26 
QuestionRe: Outlook MSG files Pin
David Crow13-Apr-13 15:32
David Crow13-Apr-13 15:32 
AnswerRe: Outlook MSG files Pin
Joe Woodbury13-Apr-13 15:56
professionalJoe Woodbury13-Apr-13 15:56 
QuestionDetecting when a file copy is complete Pin
Charles Blessing12-Apr-13 5:17
Charles Blessing12-Apr-13 5:17 
QuestionRe: Detecting when a file copy is complete Pin
David Crow12-Apr-13 5:22
David Crow12-Apr-13 5:22 
AnswerRe: Detecting when a file copy is complete Pin
Joe Woodbury12-Apr-13 8:08
professionalJoe Woodbury12-Apr-13 8:08 
GeneralRe: Detecting when a file copy is complete Pin
H.Brydon12-Apr-13 11:39
professionalH.Brydon12-Apr-13 11:39 
QuestionGet all window hadles Pin
Donguy197612-Apr-13 5:06
Donguy197612-Apr-13 5:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.