You can use TSocket to listen on a port and then talk to that port from your webserver. If you're using PHP or some language that doesn't make it real easy to work with raw sockets, you might want to consider using
Grattpd to wrap your communication in HTML (just like any regular API).
Normally you have to request access to bind to a specific port from Stefan, but you can also bind to port 0, which will randomly choose a port to bind to. Once you do this, call a script on your webserver with the port and have the webserver save the IP and port so that it can contact the gserver when necessary. Look at Grattpd for how I did this.