Struggling with a socket problem

Please can someone tell me if this is even possible, I've been trying to
come up with various solutions and none of them seem to work.

I have a model which can send UDP packets, these need to be sent over a
specific port. Users using my rails application will be able to call
the model and send a UDP packet.

However, I also need to have a script running that listens for UDP
packets arriving on the same port. This script makes calls to the same
models as the Rails application and hence I am running the script via
script/runner. The script looks something like: