Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>When sending information using sockets three ways used:</p> <p>1)fixed size message (we will use it, plus assuming we are writing on the same machine byteorder match).Simply, like we will send 100 bytes and on receive we will read 100bytes</p> <p>2)message.len + message.( first we send message len then message itself. used for binary send receive mostly)</p> <p>3)marker method (mostly used sending text messages or commands. for exampling marking with \n newline)</p> <p>Next coming on representing our data (serialize). It is easy with c cause on c we can directly write our object and retrieve it without additional efforts.Object will be the same as in memory.</p> <pre><code>// PNUMBER_THREE structAddr; send(socket_id, structAddr, sizeof(NUMBER_THREE), 0); </code></pre> <p>or </p> <pre><code> write(socket_id, structAddr, sizeof(NUMBER_THREE)); </code></pre> <p>or safer</p> <pre><code>write_socket(socket_id, structAddr, sizeof(NUMBER_THREE)); //It is safer to do so though we are using blocking mode int write_socket(int fd,const char *buf,int len){ int currentsize=0; while(currentsize&lt;len){ int count=write(fd,buf+currentsize,len-currentsize); if(count&lt;0) return -1; currentsize+=count; } return currentsize; } </code></pre> <p>when reading we will be using <strong>the same structure</strong> plus it must meet condition <code>sizeof(NUMBER_THREE)==SizeInsideClient //SizeInsideClient is sizeof on client SizeInsideClient=sizeof(NUMBER_THREE)</code></p> <pre><code> //SizeInsideClient structure size on client program assert(sizeof(NUMBER_THREE)==SizeInsideClient); readblock(socket_id,structAddr,sizeof(NUMBER_THREE)); int readblock(int fd, char* buffer, int len) { int ret = 0; int count = 0; while (count &lt; len) { ret = read(fd, buffer + count, len - count); if (ret &lt;= 0) { return (-1); } count += ret; } return count; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload