Stop server in eclipse project - java

I am developing a client server application in eclipse where the client and server connect through port 4444 to send numbers to eachother. However I am getting this error message
Address already in use: JVM_Bind
Does this mean that the port is in use? Can anyone advise me on how to fix this error?

Only one ServerSocket can bind a SocketAddress (IP address and port number).
Possible reasons why the address is already bound:
Another application on your system currently uses this port (in this case: pick another port)
You may still have a running instance of your application in the background (in this case: terminate it in the console view in Eclipse)
You attempted to bind the SocketAddress twice (in this case: fix your program).

I believe port 4444 is blocked on some routers by default. Running the command netstat -a in cmd should give you a list of all ports in use. Try using a different port if possible.

Related

How to verify if port is open

Could anyone please help me with steps how to verify if port is open/available to use.
Basically we have to verify in one of our server (windows) that
7200 port is open for use.
we have one deployment coming up, and team have end point like htts://servername::7200/index.html
If you are trying to use TCP(Transmission Control Protocol) port then run the telnet host port and see the result
connection refused means that nothing is running on that port
accepted means that something is running on that port
timeout means that a firewall is blocking access

JVisualVM remote working when destination is behind NAT?

I am in developer network and the JBoss to be monitored using JVisualVM is behind client firewall in separate network. JBoss is exposed to us through a NAT. The exposed JMX port works when using telnet from our developer network, but JVisualVM still doesn't find the remote JMX. Apparently this can be due to two things: 1) one or several dynamic RMI sockets need to be accessed, or 2) the "java.rmi.server.hostname" is not defined. My problem may be both points 1 and 2, but apparently since we have SSH access this can be tackled according to this site:
http://rafaelsteil.com/setting-up-jmx-for-jconsole-visualvm-on-ec2-plus-jetty-configuration/
“java.rmi.server.hostname” is the public hostname (like example.com) of your server, without HTTP or anything else. You cannot use an internal address, otherwise you won’t be able to remotely access the service.
However I have one question about the "java.rmi.server.hostname", should the defined IP address be the server internal IP or NAT IP which is publicly expoed to our developer network?
I have actually just tackled this problem myself and figured it out.
I would wager that the problem is the RMI connections - you can't predict which ports it will use and so you can't get it to work with a firewall.
The workaround is to use an SSH proxy:
SSH to the box where your application is running but use the -D option like this:
ssh user#remoteHost -D 9999
This will start a socks proxy on your local machine on port 9999.
Open JVisualVM and in the preferences, under 'network' configure it to use a socks proxy at localhost, on port 9999.
If you do the above, you should then be able to connect to the remote machine as normal and since all the RMI traffic is now going over the SSH proxy, it is punched through the firewall and works nicely.
Good luck :-)

Java Socket... how it works?

I have a question on Java sockets.
I'm trying to build a basic server-client connection in java using the net package classes. so to start with, I'm used the Socket class and created a socket attached to what will be the client using
address= InetAddress.getByName(ip);
socket = new Socket(address , port );
ip: is just a string representation of the ip address and port is a port number I specified to attach the socket to.
Now my question is, when I use the method getLocalPort() I get a different port number than the one I specified.Also, when I use the command 'netstat' on the command prompt I don't find the port number at which the socket is connected to in the list of active connections.
can anybody explain why is that?
port is a port number I specified to attach the socket to
No it isn't. It is the remote port number to connect the socket to. One of the problems in your question is that you are using terminology incorrectly and therefore confusing yourself.
when I use the method getLocalPort() I get a different port number than the one I specified.
No you didn't. You specified the remote port when creating the Socket. getLocalPort() returns the local port. They aren't the same thing. There is a way to specify a local port number as well, but you don't need it. That process is calling 'binding'. Neither 'bind' nor 'connect' is an 'attach'.
Also, when I use the command 'netstat' on the command prompt I don't find the port number at which the socket is connected to in the list of active connections.
You should. You should see a line with the remote IP:port in the remote column, and the state as ESTABLISHED.
That's because the port number you specify in new Socket(address , port ); is the remote port number. For example, if your remote server had a socket open on port 8123 you wanted to connect to, you'd enter new Socket(address , 8123);.
The port number you're seeing in getLocalPort() and in netstat is the port number auto-generated for your local machine socket.

java tcp connection with public i.p

I am trying to tcp connect to a server machine in java, by using its public i.p. but when i run the client application i constantly getting a connection refused error. if i used localhost instead of the public ip, it works perfectly.
i search the internet for several causes of the issue but i couldnt fix it.
i forwarded the port to my machines' local i.p address(192.168.1.3) in routers settings. then i checked if port is listening when i ran the server application using netstat -an. i saw lines like,
0.0.0.0:19999 or []:19999 .
19999 is the port number i am trying to listen to. Then i changed my ServerSocket constructor to the 3 parameter one, which also binds the local address.
InetAddress miad = InetAddress.getByAddress(addr);
ServerSocket socket1 = new ServerSocket(port,10,miad);
addr is the InetAddress of my machines local i.p. After these modifications, when i start the server application, i run netstat and it shows:
TCP 192.168.1.3:19999 0.0.0.0 LISTENING
Here i think that my server is listening on the port specified properly.
I have also disabled my firewall and antivirus software.
I have seen several threads and discussions on the net about the issue, and tried most of the things mentioned there, but i keep getting the connection refused error.
What can i be doing wrong? It runs without any errors when i test with localhost.
This is because of the router (not very sure, but almost). Try to see if a webservice like www.canyouseeme.org can connect to your server.
The main idea is that an internal machine (inside the LAN) cannot connect to a machine inside the same LAN by using the external (public) IP address.
I'm pretty sure that it will work, using you internal ip (192.168.1.3).
And if you are sure that you forwarded ports correctly, CanYouSeeMe will say your server is reachable. If it doesn't, make sure you ISP isn't blocking the ports for some kind of "safety reasons".
To figure out if your problem relates to Java and programming please do
telnet 192.168.1.3 19999
If it can't connect then superuser.com would be a better place to discuss this issue.

Java Server Client Program I/O Exception

I made this program:
http://java.sun.com/docs/books/tutorial/networking/sockets/clientServer.html
And it works perfectly if I put the server's hostname as 127.0.0.1 or my computers name (Ajay-PC).
However these 2 methods are LAN or local only not internet. So I changed it to my internet ip. 70.128.xxx.xxx etc. But it didn't work. I checked:
canyouseeme.org
and it said 4444 was CLOSED.
So I did a quick port forward.
Portforward:
Name: My Java Program
Start Port: 4444
End Port: 4444
Server IP: 10.0.0.12 <-- (Yeah this is my Local IP I checked)
then I tried
canyouseeme.org
AGAIN:
and it said 4444 was OPEN
I ran my server client program and it yet to work.
So my problem is the client server program is not working on the internet just locally. So something is blocking it and I don't know what.
EDIT: It's not blocked because as I checked the port is open. But I am recieveing a IO exception not a UnknownHost
Computer:
Windows Vista x64
Norton AntiVirus 2010
Thanks! I'll give best answer or whatever to who ever answers the best ;) :)
How do you have access to the internet? Maybe you have to configure your ADSL modem or your router/switch to forward the port 4444 to your computer.
I guess you are in the LAN if you are using a router connecting to your modem. And your computer connect to the router.
Try to connect to your modem which has your internet IP.
Have you checked that the client is connecting to port 4444 and your public IP? This is another common mistake most people make. If your port is open as you say above and the firewall is off, then there's nothing stopping you connecting.
Use Wireshark or WinDump to snoop the initial TCP handshake. Filter for packets with port 4444. Verify that the opening SYN packet is leaving your computer, that the opening SYN packet is returning to your computer, and to see what whether/how computer is responding to the opening SYN packet.
Note: if you experiment with these tools, you won't be able to use it trace if you use the localhost (127.0.0.1) and your PC IP (10.0.0.12) addresses - in these cases, the packets don't actually leave the computer and can't be snooped. Put the client and server on separate computers if you want to snoop packets on the LAN without involving the gateway.

Categories

Resources