单声道不支持 UDP 协议?
UDP protocol not supported in mono?
我不明白,因为它给了我错误代码:
Socket socket = new Socket(
AddressFamily.InterNetwork,
SocketType.Stream,
ProtocolType.Udp
);
Return 一个错误:
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 不是流协议(TCP 是)。您几乎肯定想对 UDP 使用 SocketType.Dgram
(数据报)。 UDP 代表 "User Datagram Protocol",因为它在功能上建立在数据报上。
我不明白,因为它给了我错误代码:
Socket socket = new Socket(
AddressFamily.InterNetwork,
SocketType.Stream,
ProtocolType.Udp
);
Return 一个错误:
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 不是流协议(TCP 是)。您几乎肯定想对 UDP 使用 SocketType.Dgram
(数据报)。 UDP 代表 "User Datagram Protocol",因为它在功能上建立在数据报上。