c# - Socket receive timeout throws a delayed exception -


In C #, I have a very simple server / client that is set to the timeout when getting the customer upto 500 ms This is the time, I hope that it throws an exception and does this, however, I hold it after 500ms, which is total up to a total of seconds. To check that I might have a slow machine, I test how long it takes to throw an exception, it's true that there are some snippets here.

Server thread:

  zero serverTradeProject () {(socket server = new socket (Address Family.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) {server.Bind (New IPandpoint (IPADress percie ("127.0.0.1"), 12345)); server.Listen (10); (Socket Acceptable = Server. Accept ()) using {// Wait Waiting time is so that customer times out System.Threading.Thread.Sleep (5000); accepted.Shutdown (SocketShutdown.Both); accepted.Close (); }}   

Receive trial timeout (failed):

  public should shouldnotExceedConnectionTime () {thread s = NewTrreadProc; s.Start (); (Var client = new socket (using Family.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) {client.ReceiveTimeout = 500; Client Connect ("127.0.0.1", 12345); Byte [] buf = new byte [16]; System.Diagnostics.Stopwatch Clock = New System Diagnostics Harbour (); Try {watch.Start (); client.Receive (buf); } Hold (SocketException pre) {watch.Stop (); Assurance That (ex.SocketErrorCode, Is.EqualTo (SocketError.TimedOut)); Notice. That clock (Alpex Milliseconds, East Alist (475) and. Atom (525)); }} Specifying the file ("Throw when the deadline is over"); } Result from exam:  

result message

expected: greater than or equal to or equal to 525 P>

but was: 1000

An exception throwing test (pass):

  public void throwsIntime () {System.Diagnostics.Stopwatch Watch = new system Diagnostics Harbour (); Try {watch.Start (); System.Threading.Thread.Sleep (500); Throw a new exception ("sleeping."); } Hold (exception) {watch.Stop (); Notice. That clock (Alpex Milliseconds, East Alist (475) and. Atom (525)); }}   

Has anyone seen an issue like this?

There are many references (and) in the underlying winsoc implementation of timeout, not working as expected Can. It can actually be implemented as approximately 500 MMS, as well as the value of receiver timout property. Try setting ReceiveTimeout for different values ​​and see that the timeout is actually 500ms + asset value. If this is the case then you will need to have an account for an additional 500ms in expected timeout calculations.

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -