Starting repl using:
lein repl :headless :port 4242
When I try to connect VIA cider connect I get the following error:
Connection closed unexpectedly (connection broken by remote peer)
When I try to connect VIA:
lein repl :connect 4242
I get the following error:
SocketException The transport's socket appears to have lost its connection to the nREPL server
clojure.tools.nrepl.transport/bencode/fn--5154/fn--5155 (transport.clj:95)
clojure.tools.nrepl.transport/bencode/fn--5154 (transport.clj:95)
clojure.tools.nrepl.transport/fn-transport/fn--5126 (transport.clj:42)
clojure.core/binding-conveyor-fn/fn--4676 (core.clj:1938)
java.util.concurrent.FutureTask.run (FutureTask.java:266)
java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1149)
java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:624)
java.lang.Thread.run (Thread.java:748)
Bye for now!
By default nrepl listens for connections only from the same computer. It does this by "binding" its listener to the IP address of the loopback network 127.0.0.1. If you want it to listen for connections from anywhere you can either bind it to 0.0.0.0 which is the any network address, or the address of a specific adapter.
It looks like I needed to specify the host as 0.0.0.0 e.g.
lein repl :headless :host 0.0.0.0 :port 4242
Related
When I just do lein repl it works, but when I try to connect to a host I get a refusing to connect error.
Connecting to nREPL at 127.0.0.1:7000
ConnectException Connection refused (Connection refused)
java.net.PlainSocketImpl.socketConnect (PlainSocketImpl.java:-2)
java.net.AbstractPlainSocketImpl.doConnect (AbstractPlainSocketImpl.java:400)
java.net.AbstractPlainSocketImpl.connectToAddress (AbstractPlainSocketImpl.java:243)
java.net.AbstractPlainSocketImpl.connect (AbstractPlainSocketImpl.java:225)
java.net.SocksSocketImpl.connect (SocksSocketImpl.java:402)
java.net.Socket.connect (Socket.java:591)
java.net.Socket.connect (Socket.java:540)
java.net.Socket.<init> (Socket.java:436)
java.net.Socket.<init> (Socket.java:213)
clojure.tools.nrepl/connect (nrepl.clj:184)
clojure.tools.nrepl/connect (nrepl.clj:174)
clojure.core/apply (core.clj:646)
Bye for now!
I have tried messing with my /etc/hosts:
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
But changing it did not help.
Settings:
MacOS 10.13.2
Leiningen 2.8.1 on Java 9.0.1 Java HotSpot(TM) 64-Bit Server VM
Running lein repl will start its own nREPL and connect to that. Specifying :connect 7000 won't start a REPL—it expects one to already be running on that port.
$ lein repl
nREPL server started on port 57535 on host 127.0.0.1 - nrepl://127.0.0.1:57535
REPL-y 0.3.7, nREPL 0.2.12
In a separate session you should be able to connect to your other/running REPL:
$ lein repl :connect 57535
Connecting to nREPL at 127.0.0.1:57535
REPL-y 0.3.7, nREPL 0.2.12
In the following link
http://clojure.org/reference/repl_and_main#_launching_a_socket_server
it has detailed info about how to start socket REPL form java, but since I am using lein, so how to start from lein. If start from boot is good to run, I could also try to use boot.
To start a socket repl, you need to pass this option to the JVM
-Dclojure.server.repl="{:port 5555 :accept clojure.core.server/repl}"
In Leiningen, add this to your project.clj.
:jvm-opts ["-Dclojure.server.repl={:port 5555 :accept clojure.core.server/repl}"] ; notice that the map is not quoted.
and in Boot, export the environment variable BOOT_JVM_OPTIONS
export BOOT_JVM_OPTIONS='-Dclojure.server.repl="{:port 5555 :accept clojure.core.server/repl}"'
Once your REPL is running, you can run telnet from a different terminal to connect to the socket REPL. REPLception!
$ telnet 127.0.0.1 5555
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
user=> (+ 1 1)
2
user=>
boot has an upcoming socket-server task. As of boot 2.7.1, a version that includes this task hasn't been released yet.
In the meantime you can use the following commands to launch Socket REPLs. To launch a Clojure process with a Socket REPL listening on port 50505 using boot, use:
boot -i "(do (require 'clojure.core.server) (clojure.core.server/start-server {:port 50505 :name :repl :accept 'clojure.core.server/repl}))" wait
Using Leiningen:
JVM_OPTS='-Dclojure.server.myrepl={:port,50505,:accept,clojure.core.server/repl}' lein repl
Using a pain Clojure jar:
java -Dclojure.server.myrepl="{:port 50505 :accept clojure.core.server/repl}" -jar ~/.m2/repository/org/clojure/clojure/1.8.0/clojure-1.8.0.jar
I have trouble setting up Datomic with Heroku Postgres. First of all I have this successfully installed
[com.datomic/datomic-pro "0.9.5206" :exclusions [joda-time]]
My sql-transactor.properties file looks like this:
protocol=sql
host=localhost
port=4334
license-key=<MY_LICENSE_KEY>
sql-url=jdbc:postgresql://ec2-54-204-3-200.compute-1.amazonaws.com:5432/<MY_HEROKU_DB_NAME>
sql-user=<MY_USER>
sql-password=<MY_PASS>
sql-driver-params=ssl=true;sslfactory=org.postgresql.ssl.NonValidatingFactory
When I try to run transactor from downloaded datomic-pro folder as:
bin/transactor /path/to/folder/sql-transactor.properties
It gives following output:
Launching with Java options -server -Xms1g -Xmx1g -XX:+UseG1GC -XX:MaxGCPauseMillis=50
Starting datomic:sql://<DB-NAME>?jdbc:postgresql://ec2-54-204-3-200.compute-1.amazonaws.com:5432/<MY_HEROKU_DB_NAME>?user=<MY_USER>&password=<MY_PASS>&ssl=true;sslfactory=org.postgresql.ssl.NonValidatingFactory, you may need to change the user and password parameters to work with your jdbc driver ...
System started datomic:sql://<DB-NAME>?jdbc:postgresql://ec2-54-204-3-200.compute-1.amazonaws.com:5432/<MY_HEROKU_DB_NAME>?user=<MY_USER>&password=<MY_PASS>&ssl=true;sslfactory=org.postgresql.ssl.NonValidatingFactory, you may need to change the user and password parameters to work with your jdbc driver
NOTE: The <DB-NAME> in the output is literally <DB-NAME>. It's not my placeholder. I think this might be a mistake.
Now when I try in clojure:
(def uri "datomic:sql://<MY_HEROKU_DB_NAME>?jdbc:postgresql://localhost:5432/<MY_HEROKU_DB_NAME>")
(def conn (datomic.api/connect uri))
It gives error:
java.net.ConnectException: Connection refused
org.postgresql.util.PSQLException: Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
java.util.concurrent.ExecutionException: org.postgresql.util.PSQLException: Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
clojure.lang.Compiler$CompilerException: java.util.concurrent.ExecutionException: org.postgresql.util.PSQLException: Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections., compiling:(server.clj:40:11)
Anybody any ideas?
EDIT: I forgot to mention that I already did steps from http://docs.datomic.com/storage.html about bin/sql/postgres-table script
I'm trying to connect to an nREPL from a Docker container that is running another, linked Docker container on port 7888. Despite exposing the port with -p 7888, linking the container with -link <first_container_name>:repl and using the Docker-injected environment host and port variables, I am getting a "Connection refused." error.
Here's how I run the first container:
docker run -i -t -p 7888 clojure-image lein repl :headless :port 7888
~$ nREPL server started on port 55555 on host 127.0.0.1
And the second container:
docker run -i -t -link <first_container_name>:repl clojure-image /bin/bash
username#hostname~$ lein repl :connect 172.0.2.1:7888
Why is my connection being refused? I am able to connect other services like AMQP between Docker containers.
You have to include :host 0.0.0.0 in the lein repl command to allow connections on a hostname/address other than 127.0.0.1:
lein repl :headless :host 0.0.0.0 :port 7888
You can include the port number as follows:
lein repl :headless :port 1234
If you are running on a Mac, you are probably behind boot2docker, so this article helped, a lot. Here is how I connected to the container:
lein repl :connect $(boot2docker ip):7888
And thanks to: What IP do I access when using docker and boot2docker?
I installed node.js on a hosted Apache server. The simple server I placed on the server runs fine, but when I go to the website I cannot see the website.
I initially tested this on my local machine and it works fine, but I need this on a production website. How can I do this.
My Node.js code
[code]
// Load the net module to create a tcp server.
var net = require('net');
// Setup a tcp server
var server = net.createServer(function (socket) {
// Every time someone connects, tell them hello and then close the connection.
socket.addListener("connect", function () {
sys.puts("Connection from " + socket.remoteAddress);
socket.end("Hello World\n");
});
});
// Fire up the server bound to port 7000 on localhost
server.listen(1337, "localhost");
[/code]
// Put a friendly message on the terminal
console.log("TCP server listening on port 1337 at localhost.");
Then I run node test.js
Response : TCP server listening on port 1337 at localhost.
Then I go to www.mywebsite.com:1337
Oops! Google Chrome could not connect to www.mywebsite.com:1337
So I tried using the actual IP
server.listen(1337, "xx.xx.xx.xx");
And the URL
server.listen(1337, "http://mywebsite.com");
// this actually broke the server immediatly
So how can I do this?
You will need a firewall rule to allow incoming traffic.
iptables -A INPUT -p tcp --dport 1337 -j ACCEPT
and do not bind to localhost, but on the port only:
server.listen(1337/*, "localhost"*/);
http://nodejs.org/api/net.html#net_server_listen_port_host_backlog_callback
EDIT: This comments out the host, so your server will listen on all adresses (this is the same as:)
server.listen(1337);
If you still encounter problems, this is most likely a firewall problem.