Note that there are some explanatory texts on larger screens.

plurals
  1. POReading Image from j2me to c++
    primarykey
    data
    text
    <p>I am learning c++ in order to create a little application which displays image stream. The images are coming from a j2me device which aren't stored as a file (so I just have the bytes).</p> <p>I am thinking I need to send the size of the image as an int first so then the client knows how much to read for that particular image in the stream.</p> <p>My problem is the size is always way too big - not the size of the image when I initially just try to read the size (I send this length in java server in a socket.write(int) and have tried dataoutputstream.writeInt). I will post some code as it's probably pretty simple. </p> <p>Why is the size different to what I send?</p> <pre><code> ssize_t readLine(int fd, char *buffer, size_t n) { ssize_t numRead, tt; /* # of bytes fetched by last read() */ size_t totRead; /* Total bytes read so far */ char *buf; char ch; if (n &lt;= 0 || buffer == NULL) { return -1; } buf = buffer; /* No pointer arithmetic on "void *" */ totRead = 0; for (;;) { numRead = read(fd, &amp;ch, 1); tt += numRead; if (numRead == -1) { return -1; /* Some other error */ } else if (numRead == 0) { /* EOF */ if (totRead == 0) /* No bytes read; return 0 */ return 0; else /* Some bytes read; add '\0' */ break; } else { /* 'numRead' must be 1 if we get here */ if (totRead &lt; n - 1) { /* Discard &gt; (n - 1) bytes */ totRead++; *buf++ = ch; } if (ch == '\n') break; } } printf("read line %s ", buf); fflush(stdout); int test = (int)buf; printf("read line int %i ", tt); fflush(stdout); *buf = '\0'; return totRead; </code></pre> <p>}</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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