This is a difficult question to answer. On one hand, there are too many answers. On the other hand, you haven't provided enough information. Most of the available solutions assume that your listener always runs in the background and doesn't need a logged-in GUI session.
If your listener can run in the background and doesn't need to be constantly logged in, then any solution you can find on the internet will work. That's just a basic network listener. Your only complication is that you will have to support HTTP.
Your Mac already has a full-blown web-server built in. The easiest solution would be to just enable it and use it. From there, it is merely a question of how much extra cleverness and complexity you want to add.
If you don't want to use the built-in web server, you will have to add your own code to respond to HTTP requests. Apple's APIs do support that.
You will need to use launchd to start your server automatically. You can just start your server at boot up or you can use launchd cleverness to automatically launch your app in response to activity on the listening port.
If you require a logged in user GUI session, then you will need a launchd agent to launch your app. I don't know if the other launchd cleverness will work in this case.