read from NetBuffer after using SendMessage

31 views
Skip to first unread message

aidin

unread,
May 15, 2010, 8:34:19 AM5/15/10
to lidgren-network
Awesome library!

I understand that the library is considered to "own" a NetBuffer after
passing it to SendMessage. But what if I only want to read from the
buffer or send it multiple times?

My application sometimes even have both cases (reading a buffer after
sending it x times) and I'm forced to copy the NetBuffer for every
SendMessage else my reading gets corrupted. I don't know if this is
due to the library overwriting the buffer (I've disabled buffer
recycling) or just reseting the read position.

It would be great if I could still read from the NetBuffer after using
SendMessage.

--
You received this message because you are subscribed to the Google Groups "lidgren-network" group.
To post to this group, send email to lidgren...@googlegroups.com.
To unsubscribe from this group, send email to lidgren-netwo...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/lidgren-network?hl=en.

Aidin Abedi

unread,
May 17, 2010, 6:11:07 AM5/17/10
to lidgren-network
So my question is why can't I continue reading from a buffer passed to SendMessage?

Aidin Abedi

unread,
May 17, 2010, 2:46:29 PM5/17/10
to lidgren-network
I've been digging around in NetServer.SendMessage but I can't find where it overwrites or changes the read position. I appears strange to me that this should even be the case since I don't see a reason for changing the buffer (when recyling is turned off) unless it has to do with fragmentation.

Lidgren please help me. why is my buffers getting corrupted after sending them to SendMessage?

Aidin

Enriko Riba

unread,
May 17, 2010, 3:08:59 PM5/17/10
to lidgren...@googlegroups.com

Hello,

After you issue a SendMessage the buffer is „owned“ by the lib band you are not supposed to use it anymore.

Honestly I don’t see where your problem is…in order to send a message (fill the NetBuffer) you must have the message content stored in a variable anyway, so instead trying to read from the buffer just read the variable.

 

HTH

Riki

 

Visit my projects at:

http://borgserver.sourceforge.net/index.html

http://txnagameengine.sourceforge.net


<< ella for Spam Control >> has removed Spam messages and set aside Newsletters for me
You can use it too - and it's FREE!
  www.ellaforspam.com

 

lidgren

unread,
May 17, 2010, 3:50:47 PM5/17/10
to lidgren-network
Hi!

Sorry for the slow reply. No, I don't see a reason your NetBuffer
should be corrupt or otherwise changed after being sent if recycling
is off. You can set the read position using the Position property (in
bits, not bytes!).

In gen3 this way of doing things aren't really supported tho.

--Michael


On May 17, 8:46 pm, Aidin Abedi <aidinab...@gmail.com> wrote:
> I've been digging around in NetServer.SendMessage but I can't find where it
> overwrites or changes the read position. I appears strange to me that this
> should even be the case since I don't see a reason for changing the buffer
> (when recyling is turned off) unless it has to do with fragmentation.
>
> Lidgren please help me. why is my buffers getting corrupted after sending
> them to SendMessage?
>
> Aidin
>
>
>
>
>
> On Mon, May 17, 2010 at 12:11 PM, Aidin Abedi <aidinab...@gmail.com> wrote:
> > So my question is why can't I continue reading from a buffer passed to
> > SendMessage?
>

Aidin Abedi

unread,
May 17, 2010, 5:45:25 PM5/17/10
to lidgren...@googlegroups.com
I solved it using this hacky solution:

NetBuffer dummy = new NetBuffer();
dummy.Data = buffer.Data;
dummy.LengthBits = buffer.LengthBits;

Where buffer is the original buffer and dummy points to it but has its own read position. Since this passes all my rigorous tests its obviously that only the read position gets modified by the library after SendMessage.

The reason why Im just not copying the data is simply because I don't see the need to. Why duplicate when you don't need to? 
Reply all
Reply to author
Forward
0 new messages