sockets - c# tcp server browser sometimes send extra data into buffer in multipart file upload -
sometimes multipart section of webserver recieves additional data example add binary data in middle of file. code of part:
string content = ""; content = sbuffer; int boundarycontentstart = content.indexof("boundary=") + "boundary=".length; string boundary = content.substring(boundarycontentstart, content.length - boundarycontentstart - "boundary=".length); string boundarseprator = boundary.remove(boundary.indexof("\r\n")); string temp = sbuffer; while (!content.contains(boundarseprator + "--")) { mysocket.receive(breceive, breceive.length, 0); temp = encoding.getencoding(1252).getstring(breceive); content += temp; temp = ""; }
sbuffer string recieve buffer 1024 byte array why happens , browser sends information in middle of file part in multipart form post.
whole content added conetent variable see in code above.
remember not happens. wreck files mechanism browser resend part of data server dont know? mysocket tcp socket. help
you ignoring return value of mysocket.receive(breceive, breceive.length, 0);
indicates number of bytes written buffer read, therefore re-reading data left in buffer previous read when receive
reads less breceive.length
bytes.
you should instead store return value receive
in local variable, , use overload of getstring
accepts start , length (passing length parameter).
you should check if receive reads 0 bytes, indicating connection has been closed, otherwise code enter infinite loop other side closes connection without sending expected data.
finally, depending on amount of data you're expecting, might want rethink how search boundary separator on received content. if assume content 1mb, , gets received in 1kb chunks, content.contains
first run on 1kb, 2kb, 3kb, etc. time whole 1mb has been read, have performed contains
on 500mb of data. similarly, repeated concatenation of received data content
rather inefficient new string created, requiring of data copied each time.
Comments
Post a Comment