我不明白,因为它给了我错误代码:
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 不是流协议(protocol)(TCP 是)。您几乎可以肯定要为 UDP 使用 SocketType.Dgram
(数据报)。 UDP 代表“用户数据报协议(protocol)”,因为它在功能上建立在数据报之上。
关于c# - 单声道不支持 UDP 协议(protocol)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31481231/