Click here to Skip to main content
16,014,591 members
Home / Discussions / C#
   

C#

 
GeneralRe: Can not deserialize Pin
Jacob D Dixon1-Dec-10 12:30
Jacob D Dixon1-Dec-10 12:30 
AnswerRe: Can not deserialize Pin
Luc Pattyn1-Dec-10 13:06
sitebuilderLuc Pattyn1-Dec-10 13:06 
GeneralRe: Can not deserialize Pin
Jacob D Dixon1-Dec-10 14:48
Jacob D Dixon1-Dec-10 14:48 
AnswerRe: Can not deserialize Pin
Luc Pattyn1-Dec-10 15:02
sitebuilderLuc Pattyn1-Dec-10 15:02 
GeneralRe: Can not deserialize Pin
Jacob D Dixon1-Dec-10 16:21
Jacob D Dixon1-Dec-10 16:21 
GeneralRe: Can not deserialize Pin
Luc Pattyn1-Dec-10 16:46
sitebuilderLuc Pattyn1-Dec-10 16:46 
GeneralRe: Can not deserialize [modified] Pin
Jacob D Dixon1-Dec-10 17:11
Jacob D Dixon1-Dec-10 17:11 
GeneralRe: Can not deserialize Pin
Luc Pattyn1-Dec-10 22:22
sitebuilderLuc Pattyn1-Dec-10 22:22 
If the length fits an int at the client (i.e. when it is less than 2 GB), all it takes to communicate it is the four bytes that hold the binary representation of that length value. So it will always be exactly four bytes.

One could pass that as a string (with variable length) but why do so? it only complicates matters, as then one does not know how many bytes/characters to receive, and furthermore the payload is binary data anyway, as it is using binary serialization. I probably would pass length as a string if all the data were text, but absolutely not for binary data.

Here is the receiver in pseudo-code (that looks like C# but isn't):

int length;
byte[] buffer;
int bufsize;
int lengthRequested;

startReceiver() {
    length=0;
    bufsize=1024;
    buffer=new byte[bufsize];
    installReceiveHandler(receiveHandler);
    startRead(buffer, 0, 4); // go read 4 bytes holding length
}

receiveHandler() {
    if (length==0) {
        int len=endRead();  // we hope len==4
        length=BitConverter.ToInt32(buffer);
    } else {
        int len=endRead();
        length-=len;
        // there now are len data bytes in buffer, process them
        ...
    }
    if (length<=0) {
        // we're all done, must signal caller somehow
        ...
    } else {
        // we need more data, still missing length bytes
        lengthRequested=length;
        if (lengthRequested>bufsize) lengthRequested=bufsize;
        startRead(buffer, 0, lengthRequested);
    }
}


Warning: not included are error handling, timeouts, etc.

Smile | :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.


GeneralRe: Can not deserialize Pin
Jacob D Dixon2-Dec-10 4:57
Jacob D Dixon2-Dec-10 4:57 
AnswerRe: Can not deserialize Pin
Luc Pattyn2-Dec-10 5:19
sitebuilderLuc Pattyn2-Dec-10 5:19 
GeneralRe: Can not deserialize Pin
Jacob D Dixon2-Dec-10 6:09
Jacob D Dixon2-Dec-10 6:09 
GeneralRe: Can not deserialize Pin
Luc Pattyn2-Dec-10 6:30
sitebuilderLuc Pattyn2-Dec-10 6:30 
GeneralRe: Can not deserialize Pin
Jacob D Dixon2-Dec-10 7:56
Jacob D Dixon2-Dec-10 7:56 
GeneralRe: Can not deserialize Pin
Luc Pattyn2-Dec-10 8:20
sitebuilderLuc Pattyn2-Dec-10 8:20 
QuestionTrying to deal with the memory leak in the Flash Player Pin
jbradshaw1-Dec-10 6:09
jbradshaw1-Dec-10 6:09 
AnswerRe: Trying to deal with the memory leak in the Flash Player Pin
Luc Pattyn1-Dec-10 6:52
sitebuilderLuc Pattyn1-Dec-10 6:52 
GeneralRe: Trying to deal with the memory leak in the Flash Player Pin
jbradshaw1-Dec-10 7:27
jbradshaw1-Dec-10 7:27 
QuestionRe: Trying to deal with the memory leak in the Flash Player Pin
jbradshaw1-Dec-10 7:32
jbradshaw1-Dec-10 7:32 
AnswerRe: Trying to deal with the memory leak in the Flash Player Pin
Luc Pattyn1-Dec-10 7:42
sitebuilderLuc Pattyn1-Dec-10 7:42 
GeneralRe: Trying to deal with the memory leak in the Flash Player Pin
Pete O'Hanlon1-Dec-10 9:39
mvePete O'Hanlon1-Dec-10 9:39 
GeneralRe: Trying to deal with the memory leak in the Flash Player Pin
Luc Pattyn1-Dec-10 10:09
sitebuilderLuc Pattyn1-Dec-10 10:09 
GeneralRe: Trying to deal with the memory leak in the Flash Player Pin
Pete O'Hanlon1-Dec-10 10:23
mvePete O'Hanlon1-Dec-10 10:23 
GeneralRe: Trying to deal with the memory leak in the Flash Player Pin
Luc Pattyn1-Dec-10 11:07
sitebuilderLuc Pattyn1-Dec-10 11:07 
GeneralRe: Trying to deal with the memory leak in the Flash Player Pin
DaveyM692-Dec-10 9:44
professionalDaveyM692-Dec-10 9:44 
AnswerRe: Trying to deal with the memory leak in the Flash Player Pin
Pete O'Hanlon1-Dec-10 9:12
mvePete O'Hanlon1-Dec-10 9:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.