When using Berkeley socket api, what is the data type of content that is sent over the read/send or write/recv calls? For example -
char *msg = "Our Message!";
int len, bytes_sent;
len = strlen(msg);
bytes_sent = send(sockfd, msg, len, 0);
in this code, we are using char type, but are we limited to just char type since send/write/sendto usually take void *
type. I've also seen arguments like if we send some int, it might actually be stored in little endian/big endian causing problems b/w source/dest if their endianess don't match. Then why doesn't char
type suffers from this problem too?
Also different languages like C and C++ have different size of char
too, then why isn't this a problem? If socket doesn't care any type
and just sees the content as buffer, why don't we see random corruption of data when different tcp servers/clients are written in different languages and communicate with each other?
In short, what values(type) can I send safely through sockets?
int
in C, thus they can have different size thanchar
. 2) OP stated he uses C++, so the code is C++, not C. 3) If the library you use would be relevant every C++ question would justify the C tag, because it eventually calls C code somewhere. 4) A library has no source code, but follows an ABI. Please stop adding irrelevant tags. – too honest for this site