This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Getting a requested URL page back to a Server from the Internet  RSS feed

 
Allaz Funter
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm doing an Internet Connection Sharing project where a no of clients try to access the Internet through a single connection (d main server). I've got a basic Java Browser that simply sends on the URL address ("www.java.sun.com") typed into a textfield by the user to a Server when a button is clicked. This is done thru basic read & write methods using an ObjectInput & ObjectOutputStreams. I've also created a socket connection out to the Internet by passing in the URL on port 80, thus establishing a connection... here's the code:
inet_SockCon = new Socket( InetAddress.getByName( str_Buffer ), 80 );
System.out.println( "Connected to: " +
inet_SockCon.getInetAddress().getHostName() );
The next step is trying to get the URL page requested back to the server and from there to the client browser where it will be displayed. I'm using a JEditorPane() on my Browser which formats the HTML data.
I know of the HttpURLConnection() method but does that mean my server has to be a servlet in order to deal with such a request. Also, when i set up a socket connection out to the Internet (from the code above) i don't specify the protocol (http) with it.
If anyone has any ideas as to how I can do this it would be gratefully appreciated.
Thank you.
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Allaz,
Take a look at the java.net.URLConnection class. That will setup the proper protocol for you and you should be able to relay the page back to the client.
Michael Morris
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!