Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: read page on local server

  1. #1
    Junior Member
    Join Date
    Jan 2020
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default read page on local server

    Hello,

    I have a problem. I am running a local server on esp8266 board. Now i am trying to access it with my java program on my main computer and read the contents. If i type ip into browser it opens a page and i can see the content. But when i try to read it with my java program it returns timeout exception. Could the problem be that its looking for public ips while server is on a local ip ? I tried with public domain names like google.com and it opens and reads them just fine.

    edit: well i think it doesn't even support IPs and needs a domain name. Any way around that ?


    String url = "http://192.168.4.50";
     
    		try {
     
    			URL oracle;
    			oracle = new URL(url);
     
    			BufferedReader in = new BufferedReader(new InputStreamReader(oracle.openStream()));
    			// it gets stuck here opening the inputstreamreader
     
    			String inputLine;						
     
    			while ((inputLine = in.readLine()) != null) {							
    						System.out.println(inputLine);																			
    			}		
     
    			in.close();	
     
     
    		} catch(Exception e) {
    			System.out.println("Error: " + e);			
    		}

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: read page on local server

    I get this sent to my server when I run the above code with IP address of 127.0.0.1:8080
    GET / HTTP/1.1
    User-Agent: Java/1.8.0_231
    Host: 127.0.0.1:8080
    Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
    Connection: keep-alive
    The server returns the index.html file which is printed by the code inside the loop.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Jan 2020
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: read page on local server

    I still dont understand why it is not working. I even tried to code on esp8266 that it accepts when i write in http://192.168.4.50/data.html ... i tried it with browser and its a proper html page. Anyone ?

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: read page on local server

    Is there a block from your OS? I have given permissions on my PC for java.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Jan 2020
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: read page on local server

    Oh now i am ashamed. I wrote String url = "http://192.168.4.50"; where it should be String url = "http://192.168.64.50"; No wonder i couldnt ping my server from any computer. Anyway we are moving. I tested and i can ping from java program to esp8266 server, ping gets through. I still cannot read the page, now it says connection refused.

    --- Update ---

    I am again shamed myself. When i was testing different things i left https instead of http. Now it is working. I am sorry for taking your time, i guess i am still not alright from last nights party. Happy new year everyone

Similar Threads

  1. Synchronize MySql DB from local to Server
    By m.vinay09@gmail.com in forum What's Wrong With My Code?
    Replies: 1
    Last Post: June 27th, 2013, 10:38 PM
  2. interfacing rfid reader with local web page..
    By johnz_080 in forum What's Wrong With My Code?
    Replies: 0
    Last Post: November 25th, 2012, 08:46 AM
  3. Receive Server Sent Event Notifications in JAVA SERVER PAGE (JSP)
    By amritasenthilkumar in forum Web Frameworks
    Replies: 1
    Last Post: August 17th, 2012, 02:30 PM
  4. Local Domain MySQL server, access denied
    By techwiz24 in forum JDBC & Databases
    Replies: 1
    Last Post: February 29th, 2012, 11:29 PM
  5. local NTP server
    By conanlive in forum Java Networking
    Replies: 1
    Last Post: August 12th, 2011, 04:46 AM