<html><body>On 04:53 pm, matt@zgroupplc.com wrote:<br /><br />&gt;I understand why this is occurring, its a simple matter of calling <br />&gt;tcp.Port.stopListening() to suppress the error. However, I am more <br />&gt;concerned with learning about where the most appropriate place to run &#160;this <br />&gt;routine would be. I am not happy about running it in the unit &#160;test as it <br />&gt;doesn't solve the problem, it just suppresses it.<br /><br />Putting the stopListening call into the middle of the actual test method would definitely be wrong.<br /><br />However, putting the listenTCP in the setUp and the stopListening in the tearDown would be entirely appropriate. &#160;If the code under test dynamically calls stopListening and might fail before then, then a tearDown by itself might be appropriate.<br /><br />&gt;I can't &#160;seem to find an <br />&gt;easy way to stop a port from listening from within a &#160;ServerFactory. Should <br />&gt;I be writing a class that wraps the &#160;ServerFactory to run <br />&gt;tcp.Port.stopListening() at the appropriate time?<br /><br />This is, in part, a weakness of the IProtocolFactory interface. &#160;Calls to doStart and doStop should really receive an IListeningPort argument.<br /><br />However, this is a minor wart. &#160;listenTCP returns the Port, and hooking this up to your server factory in application code should be easy enough.<br /><br />&gt;Please bear in mind that I am creating multiple 'one-shot' servers &#160;that are <br />&gt;always shut down as soon as they have done their business. I &#160;am guessing <br />&gt;that the stopService methods would be more appropriate &#160;for a conventional <br />&gt;server that serves multiple clients / requests.<br /><br />If they are "always shut down", what event currently shuts them down? &#160;Have your test trigger that event. &#160;If they're one-shot, then perhaps the method that calls listenTCP should be on the factory itself, making it even easier to keep track of the Port instance it is associated with.<br /></body></html>