Java Http Client Primer Tutorial

Java Http Client Primer Tutorial

Java Http Client Primer Tutorial

With a Mac laptop you have a Linux (Bash) environment you can access via the Terminal application. From there, if you have Java installed you can compile Java programs using the javac compiler command and then execute the resultant Java .class program (today we create ClientHttp.class via ClientHttp.java programmable source code) via java ClientHttp <URL> [<filename>] … but please note that Java works with Windows too, or Unix and Linux (only) operating systems. It is to a great degree platform-independent.

Because I started this sentence with “because”, and also because the methodology of the ClientHttp Java program today (inspired in a huge degree by Java in a Nutshell by David Flanagan pp. 189-191) which connects to a Web server (today we use our local MAMP web server via java ClientHttp http://localhost:8888/sn.html sncopy.htm … where sn.html is just this small HTML webpage, with the program output of sncopy.htm) and downloads the specified URL, is based around Sockets, so please read below, from Wikipedia … and you may want to compare and contrast this to our previous C# Socket Primer Tutorial as shown below (as well).

Hope you enjoy the tutorial in which we communicate with a local (MAMP) web server in order to download the contents of webpages of designated URLs, using Java.

Link to Socket information from Wikipedia, from where the quote in the previous tutorial below, originated.


Previous relevant C# Socket Primer Tutorial is shown below.

C# Socket Primer Tutorial

C# Socket Primer Tutorial

C# using Visual Studio on Windows is a great language to learn. If you like C# you may eventually like VB.Net, and vice versa. It has sophisticated data structures, can be Object Oriented and makes great Windows desktop applications or can be the code behind an ASP.Net website or web application.

C# and VB.Net have Visual Studio support for functionality to do with networking and the use of sockets, as described below at Wikipedia.

A network socket is an endpoint of an inter-process communication flow across a computer network. Today, most communication between computers is based on the Internet Protocol; therefore most network sockets are Internet sockets.

A socket API is an application programming interface (API), usually provided by the operating system, that allows application programs to control and use network sockets. Internet socket APIs are usually based on the Berkeley sockets standard.

A socket address is the combination of an IP address and a port number, much like one end of a telephone connection is the combination of a phone number and a particular extension. Based on this address, internet sockets deliver incoming data packets to the appropriate application process or thread.

Hope you enjoy the tutorial in which we create a socket for communications using the http protocol to a host of your choosing … we chose google.com … you will need to have your internet connection working and check that the firewall settings allow port 80 to communicate with a socket. In this tutorial we establish a socket and make a request and receive a response. In practice you would continue on with more sophistication.

Here is some downloadable C# programming source code which you might want to rename to Program.cs

The Socket Class tutorial was used and amended only slightly for this tutorial, so please start here on the path to further examination of this very interesting and fundamental area of network programming.

Link to Socket information from Wikipedia, from where the quote above came.

If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.

This entry was posted in eLearning, Networking, Tutorials and tagged , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *