Posted on 2009-04-22
Last Modified: 2013-11-23
Hi there
I am working on the following code which would enable the user to attach to a webiste/html site through the use of a socket. I do not have much experience with using a socket setup so please if you can advise me where i am missing information in the code below.



import java.util.Scanner;

class GetDataFromWebServer {

GetDataFromWebServer () throws IOException e

String address = "";

URL u = new URL (address);

URLConnection connection = u.openConnection();

final int= HTTP_PORT  = 80;

ServerSocket serverSocket = new ServerSocket (80);

InputStream ins = s.getInputStream();

OutputStream outs = s.getOutputStream();

Scanner in = new Scanner (stream);

PrintWriter out = new PrintWriterv("GET/HTTP/1.0\n\n");

String command = "GET / HTTP/1.0\n\n";


out.flush ();

while (in.hasNextLine()) {

String line = in.nextLine();

out.println (line);


public static void main (String[] args) {

try {

GetDataFromWebServer g = new GetDataFromWebServer();


catch (Exception e) {



Open in new window

Question by:Sdurrani
    LVL 17

    Assisted Solution

    Are you trying to download a webpage to a file?

    Accepted Solution


    Author Comment

    will repost with more information as right now i want to focus on the last open question as that is Very importnat to complete

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
    This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
    In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now