Scala open ports - scala

So I have been running a few scala programs on Ubunutu and I have noticed that whenever I run a program for some reason Java starts listening on some random port and won't stop listening.
I am running scala version 2.9.2 on ubuntu 14.10.
Is this meant to happen and does it happen for anyone else?
To check open ports I am using
sudo netstat -anltp
lsof -i
Thanks

Related

How to list currently running servers that are listening to localhost ports in vscode

I am using VS Code for development. After running the server as usually using npm start command (which was set up to run nodemon and the main 'app' file) I closed the terminal.
I thought that when terminal is shut down nodemon get shut down along with the terminal. Evidently this is not so as when I attempt to run npm start in the new terminal it throws an error that the port I set up my server to listen to is already in use.
Is it possible to see what servers are running currently and which ports they are listening to?
If there is no such command to list the currently running servers is there any way to shut down the running servers on the local machine without shutting down the laptop I am working on?
By the way everything mentioned above is being done on local machine and no remote server is used. Thank you in advance.
If you are on a Linux box you can run this to get the PID of any process running on that port:
Linux:
netstat -tnlp | grep {{PORT}}
This will likely find multiple lines since the number of the {{PORT}} value might show up in a PID, IP address, etc., so look through the list to find what you're looking for. The PID and process name will show up on the far right column of the result.
Example for Linux:
# netstat -tnlp | grep 443
tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 14384/nginx: master
The column on the right (14384/nginx: master) is the PID of that process, and the process name. Once you have the PID you could do a kill {{PID}} to kill that process.
The Mac version of netstat is different, and doesn't display the PID (at least not that I can tell), and I'm not sure if there's a way to do the same thing on a Windows box.

Restart PlayConsole SBT server

I'm running a scala playframework app using sbt run on intellij console. However, I exited the server using ctrl+Z instead of ctrl+D. Now, I try to sbt sbt run again, but I'm getting following exception:
java.net.BindException: Address already in use
The port is already in use. That means, previous server did not exited. If I try sbt run with different port sbt run 9999 other than default 9000, the server starts without any exception.
So, is there any way to restart or end previous session so that I will not get any binding failed exception if I run the project again?
You have another process already on that port you are using. You need to kill it or use another port.
You can list the process that are using the port and then kill them
use lsof -i:portnumber(8080)
Then kill the process using that port kill PID
Hope this helps!

Could not bind to 0.0.0.0:8080, it may be in use or require sudo

Sometimes I get this error when trying to run a Vapor application from Xcode. Reopening Xcode doesn't help, only restarting of system do. Is it a bug of the framework? What should I do to prevent this?
If using sudo does not fix this message, it means something is already bound to this port. It could be an instance of Vapor that didn't close correctly.
To fix this, you need to kill the previous instance. The easiest way to do this is:
lsof -i tcp:8080
Where 8080 is the port you are trying to use. This outputs something like:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
com.apple 4679 tanner 8u IPv4 0x890f6b0b31966939 0t0 TCP
Then kill the process bound to that port using its PID.
kill -9 4679
While Tanner's answer should help in most cases, for me the kill command had no effect and no output. So I completely quitted & restarted terminal.
When running lsof there were no processes found anymore, and issue was solved.

Having issue with Tomcat when I run in a eclipse

I am novice in java I have installed Tomcat and it runs fine in a browser but when I run in a eclipse its showing error like
Several ports (8005, 8282, 8009) required by Tomcat v7.0 Server at localhost are already in use. The server may already be running in another process, or a system process may be using the port. To start this server you will need to stop the other process or change the port number(s).
I would like to mention one thing I am not authorized to login with admin account I have tried lot to stop the already running stuff through command prompt and i followed this link Deployment error: Starting of tomcat fail
however I am getting the same error is there any way to solve this issue.
Thank You.
Some other process is using one or more of the ports needed by tomcat (8005, 8282, 8009). Probably an old instance of tomcat. Kill it, then try again.
You can run netstat -abn on windows or netstat -apn on Linux to figure out which process is listening to these ports.

Running scala program from command line fails; pasting it into interpreter succeeds

When I paste a code fragment into the scala interpreter, it works as
expected, but when I attempt to run the same file using
scala ./name-of-file.scala
It prints
<my hostname>: <my hostname>
I am on Fedora 11, and the Scala version I am using is 2.7.7final.
Does running the following command works?
ping `hostname`
If it doesn't, that's most likely your problem.
You see, because not only Scala programs run on JVM, but the Scala compiler itself runs on JVM, and the JVM has pretty steep starting times, when running scripts Scala keeps a copy of the compiler running in background as a daemon, and talks to it through a TCP connection.
Alas, it gets the IP address by resolving the hostname, which means any computer which has a hostname that is not associated to a valid IP address on that hostname will have problems.