0

Measuring time for a connected Socket

In TCP/IP C# programming i want to know for how much time the socket was connected ?(THE EXACT TIME from the day it was connected until now)

18th Aug 2018, 5:55 AM
Sogand katuzian
2 Respostas
+ 2
I don't know C#, but I know how stuff works together... ...so I cobbled something together that can query a socket for how many seconds it's been connected. This is not the exact time you requested, but it may get you started. https://code.sololearn.com/c11wNl1o9792/?ref=app
18th Aug 2018, 7:52 PM
Kirk Schafer
Kirk Schafer - avatar
+ 1
[meta approach, info by file handle] On Unix-like systems network sockets have/consume file handles*. Windows sockets v2 (winsock2) added file-like behavior for sockets, which I took to mean I could query filesystem information. When I tried this (getting a filename from the socket handle), I got a system error that I didn't know how to fix quickly, so I did the getsockopt() solution instead. If you go this route: Windows may not give you better than 2 seconds' accuracy for a file time query, depending on OS.
18th Aug 2018, 8:21 PM
Kirk Schafer
Kirk Schafer - avatar