Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

packet buffer length #19

Open
jots opened this issue Jan 31, 2015 · 1 comment
Open

packet buffer length #19

jots opened this issue Jan 31, 2015 · 1 comment

Comments

@jots
Copy link

jots commented Jan 31, 2015

how can I get Packet to write into a buffer of the exact length that is needed?
for instance, now I do:

  buf = new Buffer(1024) # too big 
  Packet.write(buf, pre)
  server.send(buf, 0, buf.length, 53, ns)
  buf = null

but I think that ends up sending too large packets in most cases.
Is there a way to get the "buf" to the correct length before sending?

@stephenwvickers
Copy link

Packet.write() returns a length which you can use:

var len = Packet.write(buf, pre)

Then use len in send():

server.send(buf, 0, len , 53, ns)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants