Hello,
I'm trying to create a very simple interaction between a client and server
program using the server-socket library which used to be part of
clojure-contrib and is now maintained by technomancy
https://github.com/technomancy/server-socket/blob/master/src/server/socket.clj
I created a simple echo server, which works fine when accessed by telnet
but can't seem to accept messages from the python client.
This is the code for the client and the server:
client.py:
import socket
s = socket.socket()
host = socket.gethostname()
port = 9001
s.connect((host,port))
while 1:
s.send("Hello")
print s.recv(1024)
s.close()
And this is the code for the server--I tried to capture all of the input
into a vector, but the vector never seems to change:
(ns bot-backend.core)
(use 'server.socket)
(import '(java.io BufferedReader InputStreamReader PrintWriter))
(def server
(create-server
9001
(fn [in out]
(binding
[*in* (BufferedReader. (InputStreamReader. in))
*out* (PrintWriter. out)]
(loop [input []]
(println input)
(recur (conj input (read-line))))))))
The only output the client displays is a single empty vector after which it
waits to receive more data. Since this works correctly when I access the
port over telnet I can't figure out what the problem is. As a novice to
both clojure and socket programming my best guess is that it has something
to do with multiple threading--I know that both python and clojure create a
new thread for each distinct socket.
It's probably an incorrect guess. That's why I've decided to consult the
community :D. Any help is appreciated in advance!
--
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.