9

I run my Spring web app on localhost, so both addresses work:

http://localhost:9999/app

http://127.0.0.1:9999/app

I would also like to see this app running on concrete IP of my machine (in order to access it from a mobile, but that is less important here). I used ipconfig to obtain my IPv4, but when I use it like so:

http://192.168.1.4:9999/app

I get 'this site can't be reached'. That's still on my local machine, not mobile. Is there something else I should set up to make it work?

EDIT: here's a PrintScreen illustrating the problem. I don't think this is a matter of app configuration, because server console should show up in all cases, even if there is no app deployed or running.

enter image description here

jarosik
  • 4,136
  • 10
  • 36
  • 53
  • your server is running on the same machine as the one you're trying to access it from, correct? Otherwise, let us know if you're on the same subnet. This makes a huge difference. – Pierre Sep 21 '16 at 17:41
  • Can you check if the port is open? Can you check if another application is using that port? Can you verify that your router is not blocking traffic? Finally, can you ensure both devices are in the same network, or at least, follow the same DHCP rules? If so, edit your question and add the details. – Bonatti Sep 21 '16 at 17:47
  • @Pierre - this is the same machine. – jarosik Sep 21 '16 at 21:44
  • The port is the same in both cases(localhost and 192.168.X.X )and it's not blocked. At this stage I'm dealing with opening this adderes on the same machine. – jarosik Sep 21 '16 at 21:45
  • Can you check in C:\Windows\System32\drivers\etc\hosts to see if there's anything backwards there (ex: putting a host first and the IP second). If they are both on the same machine, then it should not even reach the network card, this all happens in the OS = configuration issue. Also, can you try putting http:// in front of your IP, just for kicks? – Pierre Sep 22 '16 at 15:25
  • from your screenshot, I googled for issues in WildFly and wonder if you have to setup your IP as in this answer: http://stackoverflow.com/questions/26907323/jboss-wildfly-starts-but-cant-connect – Pierre Sep 22 '16 at 15:31

4 Answers4

8

all you need to do is add this to your app.properties (or whatever you called spring properties file)

server.address=<your_ip>

just as described here

Community
  • 1
  • 1
WrRaThY
  • 1,533
  • 2
  • 10
  • 14
  • shouldn't I see at least a server console? This should load without any app configuration – jarosik Sep 21 '16 at 17:35
  • I don't really know what you mean by seeing a server console, but you should configure your app :) in case you're just developing something internally - just run ipconfig, copy your address and paste it in the configuration file. In case you want it to be more stable than your DHCP ip address - check out Saraths answer – WrRaThY Sep 21 '16 at 18:55
  • I'm far from being an expert in WildFly, but I know one thing for sure. Spring and any JEE app containers don't mix well. There are things that can be managed on both Springs and containers side. Usually there are some problems involved and configuration of the container is generally more important. That said I have to ask: why did you choose WildFly? Is there anything that you need from an application server? – WrRaThY Mar 12 '17 at 00:49
1

I have the same problem. My goal is to run a Springboot application on Windows (My local computer) and allows my mobile phones to access the application.

I have solved my problem by:

1.Set static IP Address as mentioned above.

I use command prompt to run ipconfig and I can see:

IP address=192.168.1.99 
Subnet Mark=255.255.255.0 
Default gateway = 192.168.1.1  

Then I copy those values to setup the static IP.
I set preferred DSN Servr = 192.168.1.1 and I leave Alternate DNS server empty.

2. In "application.properties" file of Springboot project add server.address=192.168.1.99

Thank you for all advice above :)

poomcyber
  • 141
  • 1
  • 3
0

By default DHCP will assign you a ip address which will change. You need to set static ip address for your machine. Check this links

For Windows

http://www.howtogeek.com/howto/19249/how-to-assign-a-static-ip-address-in-xp-vista-or-windows-7/

If your operating system is not windows , you can find out instructions for your operating system to set a static ip address in internet.

Important Note:Make sure that port is allowed in your system firewall or in your antivirus settings.It won't work otherwise.

Sarath Krrish
  • 221
  • 1
  • 5
  • I have Windows 10. I completely stopped a FireWall service – jarosik Sep 21 '16 at 17:39
  • This is actually Win 7, I'm using WildFly 10 and STS 3.8.1 – jarosik Sep 21 '16 at 17:48
  • ok, so your client is windows7 and your server is windows10? That is important (not on the same machine = networking rules apply). Is your Win7 machine on the same network as the Win10 server? Ex: are both computers connected to the same router? If they are not on the same subnet, then you can't connect using an IP of the format 192.168.x.x – Pierre Sep 21 '16 at 20:23
  • This is a single machine with Win7, and there is no other (I made a mistake before, sorry for the mess). Ultimate goal is to access an app running on localhost from mobile device, but for now this is not relevant. See PrintScreen I added. – jarosik Sep 21 '16 at 22:07
0

From your screenshot and new info that "client and server are on the same machine", I googled for issues in WildFly and wonder if you have to setup your IP as in this answer: JBoss WildFly: Starts but can't connect?

Also look at this page (multihomed): http://blog.arungupta.me/bind-wildfly-different-ip-address-multihomed/ , you might need to do:

standalone.sh -b=192.168.1.4

[I'll leave this part intact in case anymore comes to this question and wants to debug similar issues]

The IP you're using [192.168.x.x] can only be used in a PRIVATE NETWORK. See: https://en.wikipedia.org/wiki/Private_network

So, it's hard to answer the question without knowing if your client and server are on the same machine, same network or different networks.

  • 1) is your client on the same machine as the server: then using that 192.168.x.x IP should work, yes. If they are on the same machine, then it should not even reach the network card, this all happens in the OS [or above] = OS or application configuration issue. Some suggestions in this case: Can you check in C:\Windows\System32\drivers\etc\hosts [/etc/hosts on *nix] to see if there's anything backwards there (ex: putting a host first and the IP second). . Also, can you try putting http:// in front of your IP, just for kicks? Otherwise: if your client is on a different machine than your server, we need to know:
    • 2) is your client and server on the same subnet (ex: connected to the same router)? If so, then you CAN use the IP of the format 192.168.x.x and your issues could be due to firewall rules on your server (or other). But we can get it to work with more details.
    • 3) is your client and server on different subnets or totally different networks altogether (ex: you try to connect from your laptop to a server on AmazonWebService or other place online). In this case, you will NOT be able to call your server with an IP of the format 192.168.x.x because that IP range in only local to its subnet. Find the PUBLIC IP for your server machine. For example, in AWS, you have private and public IPs. If your server is on a home network, you might need to setup a DMZ (Demilitarized Zone) and/or Network Address Translation so that your router can forward incoming HTTP requests to your server based on, for example, server port numbers, etc.
Community
  • 1
  • 1
Pierre
  • 2,335
  • 22
  • 40