简体   繁体   中英

UDP protocol not supported in mono?

I do not understand because it gives me error code:

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

Return an error:

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)

But my system support UDP connections:

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

That I have done wrong?

Using a SocketType.Stream for UDP doesn't work, as UDP is not a stream protocol (TCP is). You almost certainly want to use SocketType.Dgram (datagram) for UDP. UDP stands for "User Datagram Protocol" as it is functionally built on datagrams.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM