Re: Only one usage of each socket address (protocol/network address/po

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



On Thu, 31 Jan 2008 06:12:10 -0800, pbd22 <dushkin@xxxxxxxxx> wrote:

OK, thanks.
I sort of figured that but am unclear where exactly to post the stop
command.
If I do something like the below, the intllisense tells me that
listener.stop() will
never be reachable. Where, exactly, do i call stop??

Where you call it now would be fine, if you had any way to exit the loop. So, one fix is to change the loop so there's a way to exit it. :)

Personally, I wouldn't bother with the loop. I'd use the asynchronous API so that I didn't have a thread sitting blocked at a call to an Accept method, and thus I could stop and close the socket wherever I like without worrying about some thread that I needed to coordinate with.

But barring that, another alternative would be to put a try/catch around the call to AcceptTcpClient() and then just stop the listening socket from somewhere else when you need to shut down the service. Then you catch the exception that's thrown when the socket is stopped and closed, and in that way detect that it's time to exit the loop (of course, in that scenario there's no need to call Stop() after the loop, since calling Stop() and Close() would be what got you out of the loop in the first place :) ).

Pete
.



Relevant Pages

  • TCP Server+perl
    ... Client each time a new connection is established at the Socket. ... each child completes processing it closes/ends. ... # Main loop control variable ... You exit the ...
    (comp.lang.perl.misc)
  • Re: Asynchronous Programming
    ... then started them one after another in a loop. ... .Net must be using fibers or something. ... >>>> socket per thread that reads N number of packets. ... >>>> could just stop it in TaskManager without a crash. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: How Do I Use An SSLServerSocket With ServerSocketChannel?
    ... it's Java 5.0 or give up. ... endless loops of reading a socket and writing to the other one while ... loop and when it does a ServerSocket.accept, it goes into the inner loop ... isn't that going to steal a lot of CPU time ...
    (comp.lang.java.help)
  • Re: Issue with multiple threads and System.Net.Sockets.Socket
    ... first off your app has a 200 loop count, I am pritty sure you can only throw ... private thd as system.threading.thread ... private eip as string ... Are you closing the socket out? ...
    (microsoft.public.dotnet.languages.vb)
  • Re: BeginReceive return zero length buffer when run ,and work correctly when use step by step debug
    ... Your async socket listens and receives 500 bytes (your total buffer size ... receiveing end, read first 4 bytes and store size of data to come ... If I made loop around the "beginRecv until it will return the ... But the data remains on the socket, until such time as it IS ...
    (microsoft.public.dotnet.languages.csharp)