This question already has answers here:
Does TcpClient write method guarantees the data are delivered to server?
(5 answers)
Can I free my data immediately after send() in blocking mode?
(2 answers)
what happens when I write data to a blocking socket, faster than the other side reads?
(2 answers)
Closed 2 years ago.
I created this proof of concept code to exercise my understanding of how Socket.Send behaves.
The host im pointing to is actually on Australia Central azure datacenter (and im in Brazil, so its half-world distance) and yet the avg TICK is between 40 and 70. And im not talking milliseconds, TICKS!
Can anyone explain to me what is going on?
I was expecting to have the avg milliseconds close to 200 or something... but right now its not even close to 1ms!
From the docs:
[...] A successful completion of the Send method means that the underlying system has had room to buffer your data for a network send.
So there's no guarantee that the data has actually reached the destination once the Send method returns.
Related
This question already has answers here:
How do I obtain the latency between server and client in C#?
(5 answers)
Closed 4 years ago.
enter image description here
I am trying to obtain the latency time between 2 servers. So how would it be possible to obtain it in milliseconds?
Is round trip time calculated while pinging the same as latency time?
Yes, just ping the other server, it's the latency.
See this question for examples: Using ping in c#
This question already has answers here:
Is TCP 100% reliable? [closed]
(3 answers)
How reliable is a TCP connection?
(2 answers)
How reliable is .NET TCP protocol?
(5 answers)
Closed 5 years ago.
I'm currently working with the assumption that when sending TCP data with System.Net.Sockets.Socket.Send ,I am guaranteed to get an exception if the connection drops. Is it possible to have a connection drop at the OS layer without receiving a notification/exception in the C# application on top?
I don't imagine there is such a case, in .net, but how would I go about demonstrating this to someone that is skeptical.
Actually as far as i know It is possible. Imagine you create a packet send it and it gets dropped by the way. Os should automatically retransmit when ttl timesout. It will retry few times before giving up. More advanced firewalls have one small option as I remember. Drop with or without notification. Second looks like packet was 'lost' on the way to destination. They actually receive it but let's say- sends them to null without any answer.
I do not know how exactly socket.send works but from network point of view it is possible to not get confirmation for every packet that was lost/dropped.
This question already has answers here:
How to ensure all data has been physically written to disk?
(7 answers)
Closed 6 years ago.
I am developing a windows service in C# which will likely write several times per second to a log. I am currently using System.IO.File.AppendAllText(time + message) for each operation and I am concerned so many writes may wear out the disk quickly.
Could this be a problem? Should I use a stream and flush every few seconds? Does the windows disk buffer protect against this?
Why you want to reinvent the wheel?
Better use some ready framework eg. Log4Net, NLog, SeriLog.
"Should I use a stream and flush every few seconds?"
What if your app crash with no flush stream? Log go away and you don't know what happens.
This question already has answers here:
How to get memory available or used in C#
(6 answers)
Closed 9 years ago.
I'm creating a server (Console App), but after doing some long-term testing I found out it grows eating RAM. For the local test suite, I am not working with much RAM
(8GB-DDR3 #2400MHz)Is there a way (In Program.cs, I assume) to restart the program if it is using over 'x' amount of RAM? Also, one way could be a timed loop/checkup?
You can use GC.GetTotalMemory. It returns an approximate value (long) of how much memory your program has allocated.
You can create a Timer object and make this comparison under the Tick event handler.
For more information, you can look here: http://msdn.microsoft.com/en-us/library/system.gc.gettotalmemory.aspx
I agree with what others have said about fixing your memory leak.
If you want to restart your program, create a second application that monitors the first process. Then, when memory gets too high in your original app, safely shut it down and allow the second application to launch it again.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to get a specific socket and close it
I want to know a way to close an existing socket connection from a different process (In Windows). I don't have handle to the socket, I only know the port number. I think I may need to write kernel level code to do this. Any references in C#, or C++?
There are many ways to do that.
One of them is to inject a dll into the target process which will wait, for a packet or an other signal, to be sent by your main process and then close the socket.
Or you could just send a packet to the already open socket that will trigger an exception and therefore the deletion of the socket but I doubt that's going to be any easier than injecting a DLL.
Or maybe you could send a FIN signal to the open socket.