1
votes

I've just installed cURL on my hard-drive in order to use for testing with my localhost (on the command prompt). However I cannot connect to any port. You can see the directory and my input below:

C:\Users\me\curl\src>curl -v http://localhost:9000

which gives me:

  • Rebuilt URL to: http://localhost:9000/
  • timeout on name lookup is not supported
  • Trying ::1...
  • TCP_NODELAY set
  • Trying 127.0.0.1...
  • TCP_NODELAY set
  • connect to ::1 port 9000 failed: Connection refused
  • connect to 127.0.0.1 port 9000 failed: Connection refused
  • Failed to connect to localhost port 9000: Connection refused
  • Closing connection 0 curl: (7) Failed to connect to localhost port 9000: Connection refused

Perhaps I should have added that I am using IntelliJ and have since enabled cURL on the harddrive (allowing me to access it from any directory); prompting me to try the following:

C:\Users\me\scala\play\my-project>curl -v http://localhost:9000/

which returns:

  • timeout on name lookup is not supported
  • Trying ::1...
  • TCP_NODELAY set
  • connect to ::1 port 9000 failed: Connection refused
  • Trying 127.0.0.1...
  • TCP_NODELAY set
  • connect to 127.0.0.1 port 9000 failed: Connection refused
  • Failed to connect to localhost port 9000: Connection refused
  • Closing connection 0 curl: (7) Failed to connect to localhost port 9000: Connection refused

So it seems that port 9000 is not open. And I am now thinking that this needs to be configured within intelliJ - here - but this looks as though it is only supported on the Ultimate Edition. This might be the cause of the issue that I am having. It may be helpful to others but it would be good to be sure of this if anyone does have any more information.

2
Is there anyone listen on this port - Jens
I'm doing some scala programming in IntelliJ and I thought that this was how to listen/connect to the port. Do I have this wrong? - jesus g_force Harris
The issue is that there is no one listening on port 9000. You need to open a socket from another program (your server) and start listening there. Otherwise your machine tries to connect to its own 9000th port, however since nobody says "I am listening" it says "Connection refused". - H. Tugkan Kibar
@htkibar thanks. I'm not entirely sure where to do that ("open a socket from another program (your server) and start listening there"). I thought that creating a virtual server on the router as outlined here would then allow me to connect to the port but unfortunately not. - jesus g_force Harris
Think of it like this, you have opened the port (road is open) however there is no one behind it. You need an application running there to respond to you. - H. Tugkan Kibar

2 Answers

0
votes

This means that your application is not started yet (so it isn't actually listening on port 9000)

You should add a run configuration in IntelliJ (Run > Edit Configurations > + > Play 2 App) and run it before doing your curl call.

Another way to start your application is just to open a terminal in your project folder, and run sbt run.

0
votes

Try the following server code while running curl:

import java.net._
import java.io._
import scala.io._

val server = new ServerSocket(9000)
while (true) {
    val serv = server.accept()

    val in = new BufferedSource(serv.getInputStream()).getLines()
    val out = new PrintStream(serv.getOutputStream())

    out.println(in.next())
    out.flush()
    serv.close()
}