Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: SocketUDP::Receive Buffer  (Read 4249 times)

0 Members and 1 Guest are viewing this topic.

Dig

  • Newbie
  • *
  • Posts: 31
    • View Profile
SocketUDP::Receive Buffer
« on: June 09, 2009, 11:57:39 pm »
Being new to this low level network programming there is something I'm not 100% clear on here and I have an inkling its causing me big performance problems.

I can't use the sfml Packet because all the SFML functions in my engine are wrapped in Lua and Lua doesn't have a suitable method of packing data into a Packet, so I've written my own lua equivalent and then use the raw reads and write to send it.  It works but its very slow and unreliable even on a LAN.

ANYWAYS, because I don't know how big the received data is I've made a buffer that is bigger than I'd ever expect it to be (4k!!) and then called receive as usual:


Code: [Select]
Socket.Receive(Buffer, sizeof(Buffer), Received, Sender, Port

Is there a performance hit by using large buffers even if the packet are  the same size (about 20 bytes, rather than 4096 that is the size of the buffer)?    Is the rest of the buffer filled with undetermined data or does it wait until the buffer is filled before returning a full 4096 bytes worth of data?  Is it automatically a null terminated char array thats received or should the sender ensure that a null character is added?  is the null character even taken into account?

I'm lost and confused.

Nick

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
SocketUDP::Receive Buffer
« Reply #1 on: June 10, 2009, 12:23:54 am »
Quote
I can't use the sfml Packet because all the SFML functions in my engine are wrapped in Lua and Lua doesn't have a suitable method of packing data into a Packet

Can't you send your data from Lua to a C++ function, and build/send your sf::Packet from there?

Quote
Is there a performance hit by using large buffers even if the packet are the same size (about 20 bytes, rather than 4096 that is the size of the buffer)?

No. This is just wasted memory, nothing more.

Quote
Is the rest of the buffer filled with undetermined data or does it wait until the buffer is filled before returning a full 4096 bytes worth of data?

No, once a chunk of data has been received it is returned, no matter how large the target buffer is. The extra bytes are just ignored.

Quote
Is it automatically a null terminated char array thats received or should the sender ensure that a null character is added?

You don't need a null terminating character, this is not a C-style string. The size parameter is enough to retrieve the end of the data.
Laurent Gomila - SFML developer

Dig

  • Newbie
  • *
  • Posts: 31
    • View Profile
SocketUDP::Receive Buffer
« Reply #2 on: June 16, 2009, 09:27:02 am »
Quote
Can't you send your data from Lua to a C++ function, and build/send your sf::Packet from there?


In my initial attempts about six months ago it was difficult to be generic enough with this approach, but I might be wiser now so I'll give it another go.  I'd prefer it to use sf::Packet.

Your other information certainly helps sort things out, I'll keep plugging away with it all.

Cheers,
Nick

 

anything