lsalzman / enet

ENet reliable UDP networking library
MIT License
2.71k stars 669 forks source link

How do I include additional header bytes upon every enet_socket_send? #195

Closed playingoDEERUX closed 2 years ago

playingoDEERUX commented 2 years ago

Hello,

I wanted to ask how I could include additional bytes upon every enet_socket_send, I see that const ENetBuffer * buffers is passed, but I have no clue how I could add some specific extra data on top of the beginning of the entire data being sent, without destroying existing data.

I need this so I can specify some extra data to relay UDP data by telling a raw UDP proxy where to send the udp transmission units to containing the ENet payload.

I hope anyone understands my question, if not, I can provide further details. Any help is appreciated!

lsalzman commented 2 years ago

The most direct way would probably be to use the ENetCompressor callbacks. While you are not implementing a compressor, per se, that does not matter. As those callbacks exist to just munge the data in any way you want before ENet sends it or processes it. The only downside it imposes is that the result of the compress callback has to be smaller than the original data, or it will choose not to use it. But you could try modifying the source to avoid that.

More direct strategies would be like to modify enet_socket_send and enet_socket_receive directly so that internally they handle that data, but ENet never sees it. Or you could also just modify the places in the code where those functions are called, since they are only called in one place each respectively. But roughly all that still takes place at the same point the compress/decompress callbacks do.

Most roads lead to Rome here.

playingoDEERUX commented 2 years ago

image Would removing the underlined check enforce sending out compressed data that result in bigger packets?

playingoDEERUX commented 2 years ago

Also, could you perhaps make an example of appending a single byte onto the udp data that ENet sends everytime using compressor callbacks?

DrOreo002 commented 2 years ago

hey, have you found the solution for this?