 <pre><code>struct _received_data { unsigned char len_byte1; unsigned char len_byte2; char *str; } received_data; </code></pre> <p>Then, once your receive the buffer:</p> <pre><code>received_data *new_buf = (received_data*) buf; printf( "String = %s", new_buf-&gt;str); </code></pre> <p>Note that the buffers that are used in send &amp; recv are meant to carry binary data. If data being transmitted is a string, it needs to be managed (ie., adding '\0' and end of buffer etc). Also, in this case your Java server is adding length bytes following a protocol (which the client needs to be aware of).</p>