单声道不支持UDP协议

本文关键字:不支持 UDP 协议 声道 单声道 | 更新日期: 2023-09-27 18:03:20

我不明白,因为它给了我错误代码:

Socket socket = new Socket(
    AddressFamily.InterNetwork, 
    SocketType.Stream, 
    ProtocolType.Udp
);

返回错误:

me@machine:~/Demo/bin/Debug$ mono Demo.exe
Marshaling clicked signal
Exception in Gtk# callback delegate
  Note: Applications can use GLib.ExceptionManager.UnhandledException to handle the exception.
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Net.Sockets.SocketException: Protocol not supported
  at System.Net.Sockets.Socket..ctor (AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType) [0x00000] in <filename unknown>:0 
  ...
   at Gtk.Application.gtk_main()
   at Gtk.Application.Run()
   at Demo.MainClass.Main(System.String[] args)

但是我的系统支持UDP连接

me@machine:~$ nc -u -v host.com 53
Connection to host.com 53 port [udp/domain] succeeded!

我做错了吗?

单声道不支持UDP协议

使用SocketType.Stream用于UDP不起作用,因为UDP不是流协议(TCP是)。您几乎肯定希望对UDP使用SocketType.Dgram(数据报)。UDP代表"用户数据报协议",因为它在功能上建立在数据报之上。