UDP “Connect”-Speed in C#

后端 未结 2 1001
孤独总比滥情好
孤独总比滥情好 2021-01-21 05:56

I profiled some boilerplate UDP code and the speed was very good for sending only some small amount data (which is my intent).

BUT the \"connect\" method is \"very slow\

相关标签:
2条回答
  • 2021-01-21 06:05

    I have come to the following conlusion:

    There is no way to make UDP faster with C#. UdpClient with standard MSDN samples is the best choice.

    I found a wrapper for the core API of winsock: http://www.elitepvpers.com/forum/co2-programming/159327-advanced-winsock-c.html

    But when you hit "connect" (see http://msdn.microsoft.com/en-us/library/windows/desktop/ms737625(v=vs.85).aspx) the speed is rougly the same as with the managed UdpClient.

    0 讨论(0)
  • 2021-01-21 06:07

    udpClient.Connect sets the default host name and port, so subsequently you can call Send without specifying them. What's taking the time is the name resolution - translating HOSTNAME into an IPAddress.

    If you do it once in Connect, you don't have to do it every time you Send, which is faster.

    0 讨论(0)
提交回复
热议问题