Skip to content

A new sockets library for Clojure, wrapping Java sockets (UDP, TCP, SSL)

License

Notifications You must be signed in to change notification settings

billosys/sockets

Folders and files

NameName
Last commit message
Last commit date

Latest commit

21a8949 · Jul 20, 2018

History

59 Commits
May 30, 2017
Jul 20, 2018
May 30, 2017
May 30, 2017
May 30, 2017
May 30, 2017
May 27, 2017
May 30, 2017
May 27, 2017
May 27, 2017
May 30, 2017
Jul 20, 2018

Repository files navigation

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.