Why cant I access glassfish server from my local network - java

I installed netbeans with glassfish server for an ejb project.
If I enter localhost:9999/myproject/ in my browser its works.
When I also tried mylocalip:9999/myproject/ it worked.
But when I try to connect from another PC or phone on the same network I can't reach my project (pc and phone connect via wifi)
notes:
I connect to the network via wifi to router.
I turn off the firewall and add rule in the firewall with port 9999 but doesn't work.
I can't ping other devices on the wireless network.
i try to ping the address of another pc from my pc is work.
my system is windows 7
netbeans 8.0.1
glassfish 4.1

As I see you are trying to host a project on your LAN network, so all devices on your LAN can connect to it. Firstly check your settings for your server and make sure everything is alright. I suggest you take a look at Configuration > HTTP Service > HTTP Listeners and check what it is bound to. If the IP address is not your network interface address or 0.0.0.0 then change the IP address to your network interface address or 0.0.0.0. Note that after editing any settings you must restart the server. Also make sure that all are on the same LAN network (connected to the same router / Wi-Fi network). Then to connect to it hold the Windows key and press R. Run window should appear. In there type cmd and hit enter, then in the black window type ipconfig/all and look for a Local Area Connetion or Wireless LAN Adapter. At one of these there should be an IPV4 address that starts with 192.168. Use that to connect (in your case 192.168.x.xxx:9999/myproject/).
Hope I helped!

I just had the same issue..
First make sure you can ping your server
ping 192.168.xxx.xxx:9999
The make sure you have no blocking firewall (on ubuntu)
sudo ufw status
Check if your port is allowed (9999 ALLOW).
If you can't see it on the list, add it:
sudo ufw allow 9999
Happy glassfishing :)

Related

Java run ServerSocket on PC

A common problem for a common project: I'm trying to run a ServerSocket Java program on my local PC and connect to it from an Android client. As others have experienced, things go smoothly when the client connects to the local address (eg. 192.168.xxx.xxx). If I try to connect through the internet, nothing happens:
Now, here are the things I tried:
Created inbound/outbound rules in Windows Firewall to allow traffic for the Server Port (3000)
Used the public IP in the client socket (IP obtained here)
Set up port forwarding on my router: inbound connection on port 3000 are redirected to the local IP of the server (eg. 192.1686.xxx.xxx again)
Check that the IP address of the server is listening to the port 3000 using "netstat -anp tcp".
Disabled any firewall on my router, just in case.
Still, there is no connection. Using this tool (https://www.canyouseeme.org/) I triedd checking that the port was visible (with the server app running of course), but nothing, all I get is a time out.
I'm out of options, I was hoping someone could show me what I'm missing.
Thanks.
(1) Does your PC where your server runs on have a public IP?
If you haven't applied for one and are running your code in a home or working environment, your computer only has a private IP. And considering the fact, your server and client connect well in the same LAN, the problem may be the IP.
(2)If you do have a public Ip, does your server listen on all IP address or just the LAN? Check the server bind IP is '0.0.0.0', and in ServerSocket constructor you can just set it to be null.

Socket TIMEOUT when phone is on 3G, and works when on Wifi- Why?

I'm programming a client-server app, my client being an android phone, my server being my laptop.
So my issue is that this one line of code:
Socket connectionToServerSocket = new Socket(hostName, portNumber);
works perfectly fine when my cellular phone connects to the Internet with my home wifi connection, and simply times out when connected through 3G (cellular provider) eg it blocks for a while then throws a timeout exception.
The funky thing is,that I can see (using OS Monitor) that some apps are connected through very common ports, for example port #80, but switching portNumber (as well as the port that the server is listening to) to 80 doesn't help (eg it still times out), and I've tried many different ports-same result.
DNS works fine (eg it translates the logical String which I gave hostName to the correct IP) but it doesn't send the server anything...
I'm lost,what could be the reason? How can I check and resolve it?
I've run into this issue as well doing a similar application.
Your laptop and phone can connect to each other while on the same network because they share a IP address lookup through your router.
When the device is connected to the WIFI, it's request get passed through the router to check for IP addresses, it will find your laptops IP and save a request to a DNS because it can find the laptops IP already. The laptop works the same way, it finds the Ip address of the client through the router as well.
However, when your phone is on 3G, it has no way of knowing exactly where your laptop's IP address is. That's why it times out: it goes from your router to your nearest DNS (where it tries to resolve the correct IP Address), if it cannot find a domain or IP that matches it will fail.
Some steps to fix this . . .
Depending on your router you can set up port forwarding for your laptop's IP. This means incoming requests to your router can be piped to your laptop's server implementation.
Then go to any site like this http://touch.whatsmyip.org/ on your laptop to get your laptops IP. Save this to add to your clients Socket set up.
For debugging until your laptop server is visible for DNS lookup, go into your client code and add this.
Socket debugSocket = new Socket("the.laptop.ip", 80);
Some warnings:
Depending on your Router, your ip may change during restarts
With port-forwarding any browser with your ip, ex) 178.12.434.01 can log onto your laptops personal server
Future Changes:
Once a dedicated server is up and running, registered with a domain you can change the above ip parameter to "your.domain.com", and behind the scenes the actual IP address to your server will be found via DNS lookup.
the reason for that is that the server in your laptop is closed to external network by default, what you need to do is something called port forwarding
*take note: port forwarding put your server in a cyber security risk, make sure you make the right adjustments to keep your server safe.
case 1: It is working when your laptop and your phone is connected to wifi right ?
Try this once
case 2 :
connect your phone to 3G.
enable hotspot on phone.
connect your laptop to your phone's hotspot.
check the IP of your laptop if it is changed replace that in Socket object. Socket connectionToServerSocket = new Socket(newIP, portNumber);
Run your project.
Just try this once you will get what i am trying to say.
You are getting the timeout exception because your server that is
having the service is not reachable from the external network.
Hope this will help :)

localhost:8080/lio/ works great in my apachtomcat. but when i put <my ip>:8080/lio/ i get error

localhost:8080/lio/ works great in my apache tomcat, but when I use<my ip>106.5x.xx.xx:8080/lio/ I get this error:
The connection has timed out
The server at 106.5x.xx.xx is taking too long to respond.
The site could be temporarily unavailable or too busy. Try again in a few moments.
If you are unable to load any pages, check your computer's network connection.
If your computer or network is protected by a firewall or proxy, make sure that Firefox is permitted to access the Web.
In the comments you said you used whatsmyip.com for your IP adress. That is your router public IP adress and not from your PC. To get the IP from your PC do following
on Windows:
ipconfig
on Linux(needs root privileges):
ifconfig
Of course you can only access your tomcat from your local network this way. If you want to be able to access your PC from the internet you have to set up port-forwarding on your router if it is supported.

Remotely accessing Weblogic server

I installed locally and now running Weblogic Server in my machine. I can access the web application from my machine by using URL like 192.168.XXX.XXX:7001/myapp/, but I cannot access it from a different machine connected in same network. I have done this one: went to Administrative console, clicked on my server and inserted my IP in the textbox beside Listen Address.But it didn't help.
Please, help me on this matter.
The 'Listen Address' configuration item specifies which IP address your server listens on.
If it's set to 127.0.0.1 or localhost, then your server only listens on localhost address, which means it only serves requests come from localhost.
You should set it to the public IP address of your machine. Or simply set to 0.0.0.0, which means listen on all available address that your machine has.
Companies block some ports due to security reason. And 7001 is one of those common ports which they block.
So you can perform following steps.
Type following command in cmd:
telnet HOST.IP.ADDRESS PORT
Ex: telnet 192.658.152.45 7001
In case if it shows connecting and then stops, that means that port has been
blocked.
Try some other port , let say 8080.
If it works then change the default port in weblogic
Go to config.xml file in
\user_projects\domains\\config
Add listener port as
<server>
<name>AdminServer</name>
<listen-port>8080</listen-port>
<listen-port-enabled>true</listen-port-enabled>
<listen-address></listen-address>
</server>
I had the same problem and solved it like:
From the administration console change Listen address from localhost to admin server's IP
Stop Windows Firewall (I try only to define a new Rule to open port 7001 but without a result)
After that all works like a charm :)
Is your machine connected to the network?
Do you have any firewall installed? Is it blocking access from the outside?
Do you have any other software on your computer that is blocking access?
Does you network have hardware/software that blocks access to certain ports?
Other
This is a firewall issue. You can add port 7001 an exception to the firewall or before that to confirm whether the issue is because of firewall, try
systemctl stop firewalld
Check again if you are able to access the console from a different machine.
just allow specific port in firewall, Try this
sudo firewall-cmd --zone=public --permanent --add-port=7001/tcp
sudo firewall-cmd –-reload

Access dev machine localhost via usb

My activity needs to communicate with a java server located on my dev machine. Actually, using the emulator, I can access the server socket via the special 10.0.2.2 address. Now I'd like to test my app on my phone connected via usb, but it seems like I can't use 10.0.2.2 to access my dev machine localhost anymore.
Naturally using a wifi router and a proper lan addressing does the trick, but I need to use usb connection instead. Any hint ?
edit:
Just added different scenarios to let everyone understand better:
1. Emulator-based scenario:
standard java server running on my pc #localhost:15000
android java client running on my emulator.
When the android app needs to contact the server it uses 10.0.2.2:15000 like specified here.
Everything works fine.
2. Proper wifi scenario with physical connected device:
standard java server running on my pc #192.168.1.10:15000.
android java client running on my device with 192.168.1.11 address assigned.
When the android app needs to contact the server it uses 192.168.1.10:15000 and everything works fine too.
3. Desired scenario:
standard java server running on my pc #localhost:15000.
android java client running on my device connected via usb cable. No network is active.
When the android app needs to contact the server it tries to connect to 10.0.2.2:15000 but instead an exception is thrown (Network unreachable). It seems like special address 10.0.2.2 works only for emulator instances.
I just wonder if in the adb/adt suite there's a way to access pc address from the device connected via usb cable.
I hope it's a bit more clear now.
Thanks.
It seems like there's no way to let scenario #3 work properly, because usb connection is not a real network connection and there's no ip associated to it by the phone.
Actually my solution is to use an ad-hoc wifi connection between my phone and my pc. This scenario is similar to #2, but without router or dhcp. Unfortunately my Hero can't handle ad-hoc connections natively because of this issue. So I had to root my device and to change manually some config script. I hope functionality like this can be available in next releases.
You can setup a connect to your phone over USB from your dev pc, but you have to adb forward. However, I don't think you can route the otherway around over usb: setting up a connection from the phone to the pc.
You could have your pc connect to the phone and check which IP it has.
While thinking about it, I realized, using adb forward you have to use localhost as your host, so maybe you could also do this on your phone: adb forward the port you want to use and on your phone, connect to that port on localhost.

Categories