From reading what you had written, I think that using an event listener is definitely the correct way to approach your problem. Below I have provided an image of my own creation that seems to describe what you have constructed and that shows where it might be best to place the event listener.
Essentially, the client of yours will issue a cancel notification to the server via its network controller mechanism. The server will then receive that cancelation notification via its network controller which is already connected to the client via some network protocol (I am assuming TCP). When that cancellation notification from the client network controller reaches the network controller of the server, the event listener in the network controller of the server will then signal the server build manager to terminate the remote build.
Diagram of your program
I hope this helps.