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 6 of 6

Thread: Sockets and Get of Http protocol

  1. #1
    Junior Member
    Join Date
    Jan 2013
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Sockets and Get of Http protocol

    I have homework and I am completely lost. I am not fluent in java (or any other programming language). I am really struggling with these upper level java classes not knowing the basics of java. Long story on how that happened. Here is the assignment.

    Write a program in Java that uses sockets to connect to a web server on port 80, requests a web page using GET of the HTTP protocol, and displays the resulting HTML

    Ok i pretty much understand the socket thing, but i have been unable to find any info in the get of the http protocol. everything that shows up is relating to url connection, however, i don't think that is the assignment.

    here is what i have for the socket so far which i got from a youtube tutorial so i don't have that great of a grasp on it.

     
     
     
    import java.io.*;
    import java.net.*;
    public class Server  {
     
     
    	public static void main(String[] args) throws Exception 
    	{
    		Server SERVER = new Server();
    		SERVER.run();
    	}
     
    		public void run() throws Exception
    		{
    		ServerSocket one = new ServerSocket (80);
    		Socket myskt = one.accept();
    		InputStreamReader IR = new InputStreamReader(myskt.getInputStream());
    		BufferedReader BR = new BufferedReader (IR);
     
    		String message = BR.readLine();
    		System.out.println(message);
     
    		if (message != null)
    		{
    			PrintStream PS = new PrintStream (System.out);
    			PS.println ("Message Received");
    		}
    		one.close();
    		}
     
     
    	}
    Not looking for the assignment to be done for me. Just some help in the right direction please. and some links would be amazing.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Sockets and Get of Http protocol

    info in the get of the http protocol
    Get is probably the most commonly used HTTP statement. Google must have lots of pages that describe the HTTP protocol. Every time you enter a URL in the browser, it sends a GET to the site.


    Here's a site that defines the HTTP protocol:
    http://www.ietf.org/rfc/rfc2616.txt

    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Jan 2013
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Sockets and Get of Http protocol

    I have found information on the get, but most of it is the urlconnection stuff. is the GET of the HTTP protocol a part of the urlconnection or am i looking for something different since i need to use a socket to connect. it just seems pointless to use a socket if i am using the urlconnection. Im sorry I know so little about this im not even sure how to word my questions.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Sockets and Get of Http protocol

    The HTTP protocol has nothing to do with a Java class. It defines how client-server communications are to be done.
    The protocol can be used by any language. There are java classes that use the http protocol.
    If you don't understand my answer, don't ignore it, ask a question.

  5. The Following User Says Thank You to Norm For This Useful Post:

    dancer_rcd (January 28th, 2013)

  6. #5
    Junior Member
    Join Date
    Jan 2013
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Sockets and Get of Http protocol

    Ok i feel a little silly now that i get the question. I was thinking it was a class. Thank you for taking the time.

  7. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Sockets and Get of Http protocol

    Ok. Come on back if you have problems down the line.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Working With Sockets
    By andyk in forum Java Networking
    Replies: 1
    Last Post: November 27th, 2012, 07:53 PM
  2. Implement 2PC Protocol - Unable to Compile and Execute
    By The.Reaper in forum What's Wrong With My Code?
    Replies: 0
    Last Post: October 29th, 2012, 06:25 AM
  3. using XMPP protocol with java servlet
    By starz10de in forum Java Servlet
    Replies: 0
    Last Post: May 4th, 2011, 06:58 AM
  4. communication protocol
    By isaac in forum Java Networking
    Replies: 1
    Last Post: February 5th, 2010, 08:20 AM
  5. Exception (payword protocol)
    By ThodorisVon in forum What's Wrong With My Code?
    Replies: 6
    Last Post: January 27th, 2010, 01:35 PM

Tags for this Thread