hello have asked 2 questions before , have not got answer unfortunately ,but fortunately got tumble weed badge stack on flow :d here question have 2 apps 1 client 1 server simple chat messages works stuck @ position have make both applications scalable un-limited number of users ,but when 2 or 3 users sends message client simultaneously got error in second block of code here code appreciated error comes @ else block in buffer.blockcopy,
public bool handlemessage(socketasynceventargs receivesendeventargs, dataholdingusertoken receivesendtoken, int32 remainingbytestoprocess) { bool incomingtcpmessageisready = false; //create array we'll store complete message, //if has not been created on previous receive op. if (receivesendtoken.receivedmessagebytesdonecount == 0) { receivesendtoken.thedataholder.datamessagereceived = new byte[receivesendtoken.lengthofcurrentincomingmessage]; } // remember there receivesendtoken.receivedprefixbytesdonecount // variable, allowed handle prefix when // requires multiple receive ops. in same way, have // receivesendtoken.receivedmessagebytesdonecount variable, // helps handle message data, whether requires 1 receive // operation or many. if (remainingbytestoprocess + receivesendtoken.receivedmessagebytesdonecount == receivesendtoken.lengthofcurrentincomingmessage) { // if inside if-statement, got // end of message. in other words, // total number of bytes received message matched // message length value got prefix // write/append bytes received byte array in // dataholder object using store our data. buffer.blockcopy(receivesendeventargs.buffer, receivesendtoken.receivemessageoffset, receivesendtoken.thedataholder.datamessagereceived, receivesendtoken.receivedmessagebytesdonecount, remainingbytestoprocess); incomingtcpmessageisready = true; } else { // if inside else-statement, means // need receive op. still haven't got whole message, // though have examined data received. // not problem. in socketlistener.processreceive call // startreceive receive op receive more data. buffer.blockcopy(receivesendeventargs.buffer, receivesendtoken.receivemessageoffset, receivesendtoken.thedataholder.datamessagereceived, receivesendtoken.receivedmessagebytesdonecount, remainingbytestoprocess); receivesendtoken.receivemessageoffset = receivesendtoken.receivemessageoffset - receivesendtoken.recprefixbytesdonethisop; receivesendtoken.receivedmessagebytesdonecount += remainingbytestoprocess; } return incomingtcpmessageisready; }
Comments
Post a Comment