Skip to content

Latest commit

 

History

History
102 lines (67 loc) · 2.65 KB

README.md

File metadata and controls

102 lines (67 loc) · 2.65 KB

sockets

Build StatusDependencies StatusClojars ProjectTagClojure version

A Clojure wrapper for the family of Java Socket classes

Contents

Documentation

Examples

For running examples, be sure to look in the examples directory. The servers can be run with the following:

$ lein run -m examples.udp.echo-server.server

and

$ lein run -m examples.udp.quote-server.server

You can use nc (netcat) to connect to these:

$ nc -u localhost 15099

In addition, the quote server example has a client:

$ lein run -m examples.udp.quote-server.client

Usage

The following were taken from the examples mentioned above; for the full context, please see that code.

Creating a datagram socket:

(require '[sockets.datagram.socket :as socket])

(def sock (socket/create))

Creating a datagram packet implicitly with receive:

(def pkt (socket/receive sock 256))

Using the update methods with a threading macro:

(require '[inet.address :as inet]
         '[sockets.datagram.packet :as packet])

(socket/send sock
             (-> (packet/create 1)
                 (packet/update-address (inet/create [127 0 0 1]))
                 (packet/update-port port)))

License

Copyright © 2017 BilloSystems, Ltd. Co.

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.