Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

checking in initial repo

  • Loading branch information...
commit 4a668bb1aff945a6adc43ab0fe9ccf89187915e4 0 parents
Owain Lewis authored
10 .gitignore
@@ -0,0 +1,10 @@
+/target
+/lib
+/classes
+/checkouts
+pom.xml
+*.jar
+*.class
+.lein-deps-sum
+.lein-failures
+.lein-plugins
11 README.md
@@ -0,0 +1,11 @@
+# pocket
+
+Clojure utilities/dsl for sockets and network programming
+
+## Usage
+
+## License
+
+Copyright © 2012 Owain Lewis
+
+Distributed under the Eclipse Public License, the same as Clojure.
3  doc/intro.md
@@ -0,0 +1,3 @@
+# Introduction to pocket
+
+TODO: write [great documentation](http://jacobian.org/writing/great-documentation/what-to-write/)
7 project.clj
@@ -0,0 +1,7 @@
+(defproject pocket "0.1.0-SNAPSHOT"
+ :description "clojure socket utilities"
+ :url "http://github.com/owainlewis/pocket"
+ :license {:name "Eclipse Public License"
+ :url "http://www.eclipse.org/legal/epl-v10.html"}
+ :dependencies [[org.clojure/clojure "1.4.0"]]
+ :plugins [[lein-swank "1.4.4"]])
24 src/pocket/core.clj
@@ -0,0 +1,24 @@
+(ns pocket.core
+ (import [java.net ServerSocket Socket SocketException]
+ [java.io BufferedReader InputStreamReader PrintWriter]))
+
+(defn make-socket
+ "Create a new socket and catch any exceptions"
+ [host port]
+ (try (Socket. host port)
+ (catch java.io.IOException e
+ (println e))))
+
+(defn socket [host port]
+ (let [socket (make-socket host port)
+ in (BufferedReader.
+ (InputStreamReader. (.getInputStream socket)))
+ out (PrintWriter. (.getOutputStream socket))
+ conn (ref {:in in :out out})]
+ conn))
+
+(defn write [conn msg]
+ (doto (:out @conn)
+ (.println (str msg "\r"))
+ (.flush)))
+
7 test/pocket/core_test.clj
@@ -0,0 +1,7 @@
+(ns pocket.core-test
+ (:use clojure.test
+ pocket.core))
+
+(deftest a-test
+ (testing "FIXME, I fail."
+ (is (= 0 1))))
Please sign in to comment.
Something went wrong with that request. Please try again.