node-udp-proxy icon indicating copy to clipboard operation
node-udp-proxy copied to clipboard

Send Message

Open roobscoob opened this issue 4 years ago • 3 comments

Allow it to inject a message?

roobscoob avatar Oct 08 '20 22:10 roobscoob

If anyone needs a solution to this issue, I found that server.handleMessage and server.handleProxyMsg work quite well for that, where server is your UdpProxy object that you created using .createServer(options);

handleMessage allows you to send a message to the proxied server and handleProxyMsg allows you to send a message back to the peer.

For the parameters:

  • socket is the UDP socket you want to send the message to. There are different ways to get it but if you want to send a message to the proxied server you can either use server.createClient or server.connections[server.hashD(sender)] if you have a sender object. Both will return the socket object you need.
  • proxy is again the UdpProxy object (probably called server)
  • msg is your message buffer
  • sender is the sender of the UDP message

Hope this helps!

carl-vbn avatar Jun 06 '21 09:06 carl-vbn

Check out the example in the Middleware section on the readme: https://github.com/gildean/node-udp-proxy#middleware

It allows you to intercept any message, block it completely or modify it.

oronm avatar Jun 09 '21 11:06 oronm

Check out the example in the Middleware section on the readme: https://github.com/gildean/node-udp-proxy#middleware

It allows you to intercept any message, block it completely or modify it.

@roobscoob Was not asking how to modify or block a message but how to inject a new one

Allow it to inject a message?

My solution allows you to do just that.

carl-vbn avatar Jun 09 '21 12:06 carl-vbn