Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UDP Socket code in Clojure CLR

I'm trying to figure out proper syntax for interop with .Net System.Net.Sockets. My problem is the enumeration parts of the arguments. Here is the equivalent code in c#:

Socket newsock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp)

In clojure-clr I'm trying the following:

(System.Net.Sockets.Socket. (AddressFamily/InterNetwork) (SocketType/Dgram) (ProtocolType/Udp))

I'm getting CompilerException.InvalidOperationException. I reviewed https://github.com/clojure/clojure-clr/wiki/Working-with-enums regarding the enum but not understanding it.

I've also tried:

(System.Net.Sockets.Socket. (.InterNetwork AddressFamily) (.Dgram SocketType) (.Udp ProtocolType))
like image 983
casillic Avatar asked Jun 03 '26 03:06

casillic


1 Answers

Try the following

(import [System.Net.Sockets Socket AddressFamily SocketType ProtocolType])
(Socket. AddressFamily/InterNetwork SocketType/Dgram ProtocolType/Udp)
like image 56
KobbyPemson Avatar answered Jun 05 '26 15:06

KobbyPemson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!