{"id":429,"date":"2021-02-05T21:27:34","date_gmt":"2021-02-05T21:27:34","guid":{"rendered":"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/?page_id=429"},"modified":"2021-02-10T18:20:12","modified_gmt":"2021-02-10T18:20:12","slug":"networking","status":"publish","type":"page","link":"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/networking\/","title":{"rendered":"Networking"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_85 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6a6d480f68015\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6a6d480f68015\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/networking\/#Networking_Basics\" >Networking Basics<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/networking\/#Network_Communication_Protocols\" >Network Communication Protocols<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/networking\/#Host_Names_IP_Addresses\" >Host Names &amp; IP Addresses<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/networking\/#Domains\" >Domains<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/networking\/#Transport_Protocols\" >Transport Protocols<\/a><ul class='ez-toc-list-level-5' ><li class='ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/networking\/#User_Datagram_Protocol_UDP\" >User Datagram Protocol (UDP)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/networking\/#Transport_Control_Protocol_TCP\" >Transport Control Protocol (TCP)<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/networking\/#Ports\" >Ports<\/a><ul class='ez-toc-list-level-5' ><li class='ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/networking\/#Port_Numbers\" >Port Numbers<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/networking\/#The_InetAddress_Class\" >The InetAddress Class<\/a><ul class='ez-toc-list-level-5' ><li class='ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/networking\/#InetAddress_Example\" >InetAddress&nbsp;Example<\/a><\/li><\/ul><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/networking\/#Uniform_Resource_Locators_URLs\" >Uniform Resource Locators (URLs)<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/networking\/#Absolute_vs_Relative_URLs\" >Absolute vs. Relative URLs<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/networking\/#The_URL_Class\" >The URL Class<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/networking\/#Reading_from_a_URL\" >Reading from a URL<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/networking\/#Proxy_Settings\" >Proxy Settings<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/networking\/#Sockets\" >Sockets<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-18\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/networking\/#The_Socket_Class\" >The Socket Class<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-19\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/networking\/#Example\" >Example<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-20\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/networking\/#Server_Sockets\" >Server Sockets<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-21\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/networking\/#The_ServerSocket_Class\" >The ServerSocket Class<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-22\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/networking\/#Server_Example\" >Server Example<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-23\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/networking\/#Using_a_telnet_Client\" >Using a telnet Client<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-24\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/networking\/#ReverseServer_Client_Example\" >ReverseServer Client Example<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-25\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/networking\/#Multi-Threaded_Example\" >Multi-Threaded Example<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-26\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/networking\/#Web_Servers\" >Web Servers<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-27\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/networking\/#The_CGI\" >The CGI<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-28\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/networking\/#CGI_Queries\" >CGI Queries<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-29\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/networking\/#Google_Maps_Example\" >Google Maps Example<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-30\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/networking\/#The_CGI_GET_POST_Methods\" >The CGI GET &amp; POST Methods<\/a><ul class='ez-toc-list-level-5' ><li class='ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-31\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/networking\/#The_CGI_GET_Method\" >The CGI GET Method<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-32\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/networking\/#The_CGI_POST_Method\" >The CGI POST Method<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-33\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/networking\/#The_URLConnection_class\" >The&nbsp;URLConnection&nbsp;class<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-34\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/networking\/#Reading_from_a_URL_using_URLConnection\" >Reading from a URL using&nbsp;URLConnection<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-35\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/networking\/#Writing_to_a_URL_using_URLConnection\" >Writing to a URL using&nbsp;URLConnection<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-36\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/networking\/#GET_POST\" >GET &amp; POST<\/a><ul class='ez-toc-list-level-6' ><li class='ez-toc-heading-level-6'><a class=\"ez-toc-link ez-toc-heading-37\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/networking\/#The_CGI_GET_Method-2\" >The CGI GET Method<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-6'><a class=\"ez-toc-link ez-toc-heading-38\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/networking\/#The_CGI_POST_Method-2\" >The CGI POST Method<\/a><\/li><\/ul><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-39\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/networking\/#Extended_Example\" >Extended Example<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-40\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/networking\/#Posting_Form_Data\" >Posting Form Data<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-41\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/networking\/#Alternative_Post_Example\" >Alternative Post Example<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-42\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/networking\/#Alternatives_for_Coding_for_the_Web\" >Alternatives for Coding for the Web<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n\n<p class=\"wp-block-paragraph\">If you&#8217;re interested in doing anything with the Internet, or anything with local area network (LAN), then you need to know something about networking.&nbsp; Java provides very good support for networking, and it&#8217;s quite easy to use.&nbsp; Indeed, that&#8217;s one significant reason why Java has become so popular and successful.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Networking_Basics\"><\/span>Networking Basics<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Here is a short introduction to some of the basics of computer networking, and how Java supports it.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Network_Communication_Protocols\"><\/span>Network Communication Protocols<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Computers communicate with each over the Internet using a number of protocol layers:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>Application Layer<\/strong><br>(HTTP, ftp, telnet, gopher, etc)<\/td><\/tr><tr><td><strong>Transport Layer<\/strong><br>(TCP, UDP, etc)<\/td><\/tr><tr><td><strong>Network Layer<\/strong><br>(IP, etc)<\/td><\/tr><tr><td><strong>Link Layer<\/strong><br>(device driver, etc)<\/td><\/tr><\/tbody><\/table><figcaption>This is not a complete description of all the layers.<br>Each layer uses its own set of protocols that rely on the lower layers<\/figcaption><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Host_Names_IP_Addresses\"><\/span>Host Names &amp; IP Addresses<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Every computer on the Internet has at least one&nbsp;<strong><em>host nam<\/em>e<\/strong> and at least one&nbsp;<em><strong>IP address.<\/strong>&nbsp;<\/em>IP addresses provide a unique identifier for each machine.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Host names provide a convenient name for human consumption, and there is a mapping between a host name and an IP address. The mapping of host name to IP address is, in general,&nbsp;1:n. That is, a host machine may have one or more IP addresses. Typically, a machine has one IP address for each network interface card (NIC) it has installed.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">IP addresses are 32-bit numbers which usually are represented like: <strong>207.46.130.14<\/strong>, where each group of digits represents 8 bits of the 32-bit number, and is usually expressed in decimal.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>Actually, <strong>IPv4<\/strong>&nbsp;uses a 32-bit address for its Internet addresses. When it looked like they would soon run out of IPv4 addresses, they introduced IPv6. <strong>IPv6<\/strong>&nbsp;utilizes 128-bit Internet addresses. Therefore, it can support 2<sup>128<\/sup> Internet addresses \u2014340,282,366,920,938,463,463,374,607,431,768,211,456 of them to be exact. The number of&nbsp;<strong>IPv6<\/strong>&nbsp;addresses is 1028 times larger than the number of&nbsp;<strong>IPv4<\/strong>&nbsp;addresses.<\/p><\/blockquote>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>See&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/bhiggs.x10hosting.com\/Courses\/HighOctaneJava\/Networking\/Basics\/InetAddress.htm\" target=\"_blank\">later<\/a>&nbsp;for how to discover the IP address for a given host.<\/p><\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">There is a special host name,&nbsp;<strong>localhost<\/strong>, which translates to a special IP address,&nbsp;<strong>127.0.0.1<\/strong>, which represents the local machine, specific to programs running on that machine.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Domains\"><\/span>Domains<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Host names exist within Internet&nbsp;<em>domains<\/em>. Domains provide a hierarchical naming convention to conveniently divide up the world of Internet host names. For example, consider the host name:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>purchasing.ebaubles.com<\/strong><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Here:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>purchasing<\/strong>&nbsp;is a host name within the&nbsp;<strong>ebaubles.com<\/strong>&nbsp;domain<\/li><li><strong>ebaubles<\/strong>&nbsp;is a domain within the&nbsp;<strong>com<\/strong>&nbsp;domain<\/li><li><strong>com<\/strong>&nbsp;is the domain for all US&nbsp;<em><strong>commercial<\/strong><\/em>&nbsp;sites.<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Non-US names tend to append a name to indentify the country. For example:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>benefits.porkpiesareus.co.uk<\/strong><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Back when the&nbsp;Domain Name System was invented, there were initially seven (7) domains you could choose from:&nbsp;<em>.com, .net, .gov, .org, .edu, .mil, .arpa<\/em>. These domains are called&nbsp;<strong>Top-Level Domains (TLDs)<\/strong>&nbsp;and supposedly, each one had a different purpose: <\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>.com<\/strong> was for \u201ccommercial\u201d purposes, <\/li><li><strong>.net<\/strong> for \u201cnetwork\u201d companies, <\/li><li><strong>.gov<\/strong> for \u201cgovernment institutions\u201d, <\/li><li><strong>.org<\/strong> for \u201cnon-profit organizations\u201d,&nbsp;<\/li><li><strong>.edu<\/strong> for \u201ceducation\u201d, <\/li><li><strong>.mil<\/strong> for \u201cmilitary\u201d and <\/li><li><strong>.arpa<\/strong> for \u201cinfrastructure\u201d (it stood for Advanced Research Projects Agency, the agency that created the internet)<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">It soon became obvious though, that it was important for countries to have their own, country-specific domain extensions instead of just having the generic ones mentioned above. So, a new top-level domain category was invented called&nbsp;<strong>Country Code Top-Level Domains (ccTLDs)<\/strong>. These ccTLDS are exclusively to countries, for example:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>.fr<\/strong> for France, <\/li><li><strong>.de<\/strong> for Germany, <\/li><li><strong>.gr <\/strong>for Greece, <\/li><li><strong>.jp<\/strong> for Japan, <\/li><li><strong>.uk<\/strong> for the United Kingdom, etc.<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">To further confuse things, some countries decided to have a \u201c.co.\u201d before their ccTLDs: for example, amazon<strong>.co.uk<\/strong>&nbsp;(United Kingdom), australia<strong>.gov.au<\/strong> (Australia) or google.<strong>com.mx&nbsp;<\/strong>(Mexico).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Each and every country has the right to choose whether to use just its ccTLD (that would be name.jp for Japan) or also add a sub-domain (such as name.co.za for South Africa). There are no world-wide regulations as to the domain each country will use \u2013 it\u2019s entirely up to them. Some prefer to add the sub-domain in order to distinguish between commercial (<strong>example.co.uk<\/strong>), government (<strong>example.gov.uk<\/strong>) or education (<strong>example.gov.uk<\/strong>). Others don\u2019t share this opinion and only use their ccTLD.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Transport_Protocols\"><\/span>Transport Protocols<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">There are two major transport protocols used on the Internet:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><em>User Datagram Protocol <\/em>(UDP)<\/li><li><em>Transport Control Protocol<\/em> (TCP)<\/li><\/ul>\n\n\n\n<h5 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"User_Datagram_Protocol_UDP\"><\/span>User Datagram Protocol (UDP)<span class=\"ez-toc-section-end\"><\/span><\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">A&nbsp;<em>Connectionless Protocol<\/em>. Provides for communication that is not guaranteed between two applications on the Internet. It acts rather like the postal service, where letters and packages are sent, but delivery is not guaranteed, and multiple pieces of mail are independent of each other, and may arrive in a different order from the order in which they were sent.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">UDP uses independent, self-contained packets of data called&nbsp;<em>datagrams<\/em>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Some applications don&#8217;t need reliable, guaranteed delivery of messages. A time service, or the&nbsp;ping&nbsp;service are examples.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Transport_Control_Protocol_TCP\"><\/span>Transport Control Protocol (TCP)<span class=\"ez-toc-section-end\"><\/span><\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">A&nbsp;<em>Connection-oriented Protocol<\/em>. Provides for reliable communication between two applications on the Internet. It is analogous to making a telephone call: One side initiates the connection and the other side answers; messages are sent back and forth over the connection, and they arrive in the same order in which they were sent. The protocol guarantees the messages sent actually arrive, or else an error is reported.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Most application level protocols (such as&nbsp;HTTP,&nbsp;ftp,&nbsp;telnet, etc.) rely on the TCP protocol to ensure that the data sent back and forth actually arrives, and in the proper order.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Ports\"><\/span>Ports<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Typically, each computer on the Internet has a single physical connection to the network. However, a computer may have several applications that use data sent over that single physical connection. There must be a way of identifying which data is associated with which application. This is done by means of&nbsp;<em>ports<\/em>. A port is a connection point identified by a&nbsp;<em>port number<\/em>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Typically, a specific application, such as a <em>web server <\/em>or a&nbsp;<em>telnet&nbsp;service<\/em>, will grab a particular port and expect clients to connect to that port in order to use the service provided by that application. Conventions have been set up to standardize port numbers for such applications.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Port_Numbers\"><\/span>Port Numbers<span class=\"ez-toc-section-end\"><\/span><\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">Port numbers are assigned by the <strong>Internet Assigned Numbers Authority <\/strong>(<a rel=\"noreferrer noopener\" href=\"http:\/\/www.iana.org\/\" target=\"_blank\">IANA<\/a>), and are divided into three ranges: the&nbsp;<em>Well Known Ports<\/em>, the&nbsp;<em>Registered Ports<\/em>, and the&nbsp;<em>Dynamic and\/or Private Ports<\/em>.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><th>Port Type<\/th><th>Port Range<\/th><\/tr><tr><td><strong>Well Known Ports<\/strong><\/td><td><strong>0 through 1023<\/strong><\/td><\/tr><tr><td><strong>Registered Ports<\/strong><\/td><td><strong>1024 through 49151<\/strong><\/td><\/tr><tr><td><strong>Dynamic<\/strong>&nbsp;or&nbsp;<strong>Private Ports<\/strong><\/td><td><strong>49152 through 65535<\/strong><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Here are some examples of Well Known Ports:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>echo<\/strong><\/td><td><strong>7<\/strong><\/td><\/tr><tr><td><strong>daytime<\/strong><\/td><td><strong>13<\/strong><\/td><\/tr><tr><td><strong>FTP<\/strong><\/td><td><strong>21<\/strong><\/td><\/tr><tr><td><strong>telnet<\/strong><\/td><td><strong>23<\/strong><\/td><\/tr><tr><td><strong>SMTP<\/strong><\/td><td><strong>25<\/strong><\/td><\/tr><tr><td><strong>finger<\/strong><\/td><td><strong>79<\/strong><\/td><\/tr><tr><td><strong>HTTP<\/strong><\/td><td><strong>80<\/strong><\/td><\/tr><tr><td><strong>POP3<\/strong><\/td><td><strong>110<\/strong><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"The_InetAddress_Class\"><\/span>The InetAddress Class<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">The&nbsp;<strong>InetAddress<\/strong>&nbsp;class encapsulates Internet addresses. It supports both host names and IP addresses.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>InetAddress<\/strong>&nbsp;is a somewhat unusual class, because it has no public constructors. To get an instance of&nbsp;<strong>InetAddress<\/strong>, you use one of the&nbsp;static&nbsp;methods in the class.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To learn about the javadoc details of the <strong>InetAddress<\/strong> class, click&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/docs.oracle.com\/javase\/1.5.0\/docs\/api\/java\/net\/InetAddress.html\" target=\"_blank\">here<\/a>.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"InetAddress_Example\"><\/span>InetAddress&nbsp;Example<span class=\"ez-toc-section-end\"><\/span><\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s an example program that uses the <strong>InetAddress<\/strong> class to perform a lookup on a specified host:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; auto-links: false; title: ; quick-code: false; notranslate\" title=\"\">\npackage networking;\n\nimport java.net.InetAddress;\nimport java.net.UnknownHostException;\nimport java.util.Scanner;\n\n\/**\n *   Application to perform a lookup on the specified host.\n *\/\npublic class NodeLookup\n{\n  \/**\n   * Main entry point\n   * @usage java networking.NodeLookup hostname\n   * \n   * If no arguments provided, will prompt for hostname\n   * \n   * @param args the command line arguments\n   *             args&#x5B;0] contains the hostname to look up\n   *\/\n  public static void main(String&#x5B;] args)\n  {\n    String hostName;\n    \n    if (args.length &lt; 1)\n    {\n      System.out.print(&quot;Hostname to look up: &quot;);\n      Scanner in = new Scanner(System.in);\n      hostName = in.nextLine();\n    }\n    else\n    {\n      hostName = args&#x5B;0]; \/\/ Use first argument for hostname\n    }\n    \n    try\n    {\n      InetAddress host = InetAddress.getByName(hostName);\n      System.out.println(&quot;Host name : &quot; + host.getHostName());\n      System.out.println(&quot;IP address: &quot; + host.getHostAddress());\n    }\n    catch (UnknownHostException e)\n    {\n      System.out.println(&quot;Unknown host&quot;);\n    }\n  }\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">If you ask it to look up the host&nbsp;<strong>java.net<\/strong>, it will output:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>Host name : java.net\nIP address: 137.254.56.25<\/strong><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If you ask it to do the reverse lookup on <strong>137.254.56.25<\/strong>, it will tell you:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>Host name : lb-javanet-cms-adc.oracle.com\nIP address: 137.254.56.25<\/strong><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">(So it&#8217;s now clear that java.net is owned by Oracle)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you ask it to look up&nbsp;<strong>localhost<\/strong>, it will output:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>Host name : localhost\nIP address: 127.0.0.1<\/strong><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If you ask it to look up&nbsp;<strong>127.0.0.1<\/strong>, it will output the same as for&nbsp;localhost:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>Host name : localhost\nIP address: 127.0.0.1<\/strong><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"url\"><span class=\"ez-toc-section\" id=\"Uniform_Resource_Locators_URLs\"><\/span>Uniform Resource Locators (URLs)<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A URL is a&nbsp;<em>Uniform Resource Locator<\/em>, and is a reference to a resource on the Internet.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You have used URLs to find web pages in your Internet web browser. For example, here is the URL used to access the JavaSoft home page:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"http:\/\/www.java.com\/\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>http:\/\/www.java.com\/<\/strong><\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The parts of this URL are as follows:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>http<\/strong>&nbsp;is the&nbsp;<em>Protocol Identifier<\/em>, or <em>Scheme<\/em>&nbsp;&#8212; in this case, identifying the&nbsp;HTTP&nbsp;protocol. Protocol identifiers include (there are others):<ul><li><strong>http<\/strong>&nbsp;&#8212; The HyperText Transfer Protocol<\/li><li><strong>ftp<\/strong>&nbsp;&#8212; The File Transfer Protocol<\/li><li><strong>gopher<\/strong>&nbsp;&#8212; The gopher protocol<\/li><li><strong>mailto<\/strong>&nbsp;&#8212; The mailto protocol (typically invokes email client)(Protocol names are also known as&nbsp;<dfn>schemes<\/dfn>.)<\/li><\/ul><\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>:&nbsp;(colon)<\/strong> separates the Protocol Identifier from the Resource Name<\/li><li><strong>www.java.com\/<\/strong>&nbsp;is the&nbsp;<em>Resource Name<\/em>&nbsp;&#8212; in this case, identifying the host name&nbsp;www.java.com<\/li><\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>Occasionally, you might see an explicit port number specified within the URL. That is the port number to contact at the resource for the HTTP protocol to use. By default, the HTTP port is 80, but sometimes you may see other ports specified. For example:<\/p><\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"http:\/\/www.example.com:1030\/software\/index.html\">http:\/\/www.example.com:1030\/software\/index.html<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you click on the <strong><a rel=\"noreferrer noopener\" href=\"http:\/\/www.java.com\/\" target=\"_blank\">http:\/\/www.java.com\/ <\/a><\/strong> link, you will find that it takes you to:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/www.java.com\/en\/\"><strong>https:\/\/www.java.com\/en\/<\/strong><\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The <strong>http:\/\/<\/strong> protocol has been automatically converted to the <strong>https:\/\/ <\/strong>protocol, which is more secure, and is now preferred and strongly recommended for all websites. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Note that browsers nowadays often suppress the display of http\/https and the www prefix, in their address bar. <\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>The www is often, but not always, optional &#8212; sometimes, if you omit it, it will be automatically added; sometimes, if you included it, it will be automatically be removed. Sometimes, websites are picky about you having to include it, or not.<\/p><\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">Note that the full resource name consists of:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>the <strong>hostname<\/strong> (including domain)<\/li><li>a forward slash (<strong>\/<\/strong>)<\/li><li>and a <em>path<\/em><\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">The path identifies the specific resource in the host that the web client wants to access. For example,&nbsp;<samp><strong>\/software\/htp\/cics\/index.html<\/strong><\/samp>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In the above case, the <strong>\/en\/ <\/strong>specifies the English version of the website.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>Take a look at <strong>https:\/\/www.java.com\/de\/<\/strong> to see an alternative language!<\/p><\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">Finally, there can be an additional component to the URL: a query string, which is prefixed by a question mark (<strong>?<\/strong>). If a query string is present, it follows the path, and provides a string of information that the resource can use for some purpose (for example, as parameters for a search, or as data to be processed. Typically, a query string is a list of name\/value pairs, separated from each other by an ampersand (<strong>&amp;<\/strong>). For example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>?term=spring&amp;course=physics<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Here is the syntax of an <strong>https<\/strong> URL:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>                            .-:80-----.                      \n&gt;&gt;-http:\/\/--+-host name--+--+---------+--\/--path component------&gt;\n            '-IP address-'  '-:--port-'                      \n\n&gt;--+-----------------+-----------------------------------------&gt;&lt;\n   '-?--query string-'   <\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">One more item you may find in a URL:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A <strong>Reference<\/strong> (aka <strong>Anchor<\/strong>), which is preceded by a hash (<strong>#<\/strong>), and provides the name of an anchor within a webpage, so that the browser may go to that part of the webpage directly.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example: <a href=\"#url\">#url<\/a> (see Relative URLs, below).<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Absolute_vs_Relative_URLs\"><\/span>Absolute vs. Relative URLs<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">The URLs shown in the previous sections are examples of&nbsp;<em>absolute URLs<\/em>. That is, they contain all the information (perhaps defaulted) necessary to find a resource on the Internet.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">There are also&nbsp;<em><strong>relative URLs<\/strong><\/em>, which allow you to access resources relative to a known location. For example, it is very common to use relative URLs within an HTML document:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>#Example<\/strong>&nbsp;&#8212; refers to the anchor&nbsp;<strong>Example<\/strong>&nbsp;in the current page<\/li><li><strong>images\/myFamily.gif<\/strong>&nbsp;&#8212; refers to the&nbsp;<strong>myFamily.gif<\/strong>&nbsp;file within the&nbsp;images&nbsp;subdirectory on the host which supplied the current page.<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Relative URLs are very useful, because they allow you to move whole sets of resources around, without having to change all the mutual references, links, etc that they contain.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"The_URL_Class\"><\/span>The URL Class<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">In Java, you can use the&nbsp;URL&nbsp;class to construct a URL object.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Take a look at the API documentation for the URL class by clicking&nbsp;<a href=\"http:\/\/java.sun.com\/j2se\/1.5.0\/docs\/api\/java\/net\/URL.html\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Using the URL class you can construct URLs from pieces, which might involve absolute or relative URLs:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>URL java = new URL(\"http:\/\/www.java.com\/\");<\/strong><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>URL gamelan = new URL(\"http:\/\/www.gamelan.com\/pages\/\");\nURL gamelanGames = new URL(gamelan, \"Gamelan.game.html\");\nURL gamelanNetwork = new URL(gamelan, \"Gamelan.net.html\");<\/strong><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>new URL(\"http\", \"www.gamelan.com\", \"\/pages\/Gamelan.net.html\");<\/strong><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>new URL(\"http\", \"www.gamelan.com\", 80, \"\/pages\/Gamelan.net.html\");<\/strong><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s an example of a program that uses this class to display a web page:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; auto-links: false; title: ; quick-code: false; notranslate\" title=\"\">\npackage networking;\n\nimport java.awt.BorderLayout;\nimport java.awt.Color;\nimport java.awt.EventQueue;\nimport java.awt.event.ActionEvent;\nimport java.awt.event.ActionListener;\n\nimport java.net.URL;\nimport javax.swing.BorderFactory;\nimport javax.swing.JButton;\nimport javax.swing.JEditorPane;\nimport javax.swing.JFrame;\nimport javax.swing.JPanel;\nimport javax.swing.JScrollPane;\nimport static javax.swing.WindowConstants.EXIT_ON_CLOSE;\n\n\/**\n *   Program to display a webpage, given its URL.\n *\n *   @author Bryan J. Higgs, 9 October 1999\n *\/\npublic class ShowDocument extends JFrame\n{\n  public static void main(String&#x5B;] args)\n  {\n    EventQueue.invokeLater( new Runnable()\n      {\n        public void run()\n        {\n          ShowDocument frame = new ShowDocument();\n          frame.setDefaultLookAndFeelDecorated(true);\n          frame.setDefaultCloseOperation(EXIT_ON_CLOSE);\n          frame.setTitle(&quot;Show Document&quot;);\n          frame.setBounds(200, 200, 800, 500);\n          frame.setVisible(true);\n        }\n      }\n    );\n\n  }\n  \n  public ShowDocument()\n  {\n    JPanel contentPane = (JPanel) getContentPane();\n    contentPane.setLayout( new BorderLayout() );\n    contentPane.add(m_button, BorderLayout.SOUTH);\n    \n    JScrollPane scrollPane = new JScrollPane();\n    JEditorPane editorPane = new JEditorPane();\n    editorPane.setEditable(false);\n    scrollPane.setViewportView(editorPane);\n    contentPane.add(scrollPane, BorderLayout.CENTER);\n    \n    m_button.addActionListener( new ActionListener()\n    {\n      public void actionPerformed(ActionEvent event)\n      {\n        \/\/ Postpone the work to add the URL contents\n        \/\/ to the editor pane\n        EventQueue.invokeLater(new Runnable()\n        {\n          public void run()\n          {\n              try\n              {\n                \/\/ Open the URL in the editor pane\n                editorPane.setPage( new URL(m_urlToDisplay) );\n              }\n              catch (Exception ex)\n              {\n                  \/\/ Should never happen because we&#039;re\n                  \/\/ hardcoding a valid URl.\n                  ex.printStackTrace();\n              }\n          }\n        }\n        );\n      }\n    }\n  );\n }\n  \n  \/\/\/\/ Private data \/\/\/\/\n  private static final String m_urlToDisplay \n     = &quot;http:\/\/help.websiteos.com\/websiteos\/example_of_a_simple_html_page.htm&quot;;\n  \n  private JButton m_button  = new JButton(&quot;Click to display webpage&quot;);\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">which produces the following:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"alignleft size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"645\" src=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-content\/uploads\/2021\/02\/Screen-Shot-2021-02-07-at-12.30.14-PM-1024x645.png\" alt=\"\" class=\"wp-image-450\" srcset=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-content\/uploads\/2021\/02\/Screen-Shot-2021-02-07-at-12.30.14-PM-1024x645.png 1024w, https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-content\/uploads\/2021\/02\/Screen-Shot-2021-02-07-at-12.30.14-PM-300x189.png 300w, https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-content\/uploads\/2021\/02\/Screen-Shot-2021-02-07-at-12.30.14-PM-768x484.png 768w, https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-content\/uploads\/2021\/02\/Screen-Shot-2021-02-07-at-12.30.14-PM-1536x968.png 1536w, https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-content\/uploads\/2021\/02\/Screen-Shot-2021-02-07-at-12.30.14-PM.png 1612w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n\n<div style=\"height:23px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">where I&#8217;ve already clicked the &#8220;Click to display webpage&#8221; button.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>Note that more complex webpages will take longer to display, and if they use JavaScript or other complex features, they won&#8217;t display as well, or even not at all. I intentionally picked a very straightforward and short webpage in the above example to avoid such issues.<\/p><p>This emphasizes that using a JEditorPane does not constitute implementing a complete browser.<\/p><\/blockquote>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"reading-from-a-url\"><span class=\"ez-toc-section\" id=\"Reading_from_a_URL\"><\/span>Reading from a URL<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">The&nbsp;<strong>URL<\/strong>&nbsp;class provides a method:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>public InputStream openStream()<\/strong><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Remember, however, that if you wish to read&nbsp;<strong><em>text<\/em><\/strong> from this stream, you must wrap it inside an&nbsp;<strong>InputStreamReader<\/strong>, as we discussed in the I\/O section.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s an application that makes use of this method to read text from a specified URL:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; auto-links: false; title: ; notranslate\" title=\"\">\npackage networking;\n\nimport java.net.URL;\n\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.Scanner;\n\n\/**\n *   Application to read text from a URL\n *   specified in the first command line argument.\n *   (Note that this is NOT a Reader, like BufferedReader.)\n *\/\npublic class URLReader\n{\n  \/**\n   * \n   * @usage java networking.NodeLookup urlstring\n   * \n   * If no arguments provided, will prompt for urlstring\n   * \n   * @param args the command line arguments\n   *             args&#x5B;0] contains the urlstring to read\n   *\/\n  public static void main(String&#x5B;] args) throws Exception\n  {\n    String urlName;\n    \n    if (args.length &lt; 1)\n    {\n      System.out.print(&quot;URL : &quot;);\n      Scanner in = new Scanner(System.in);\n      urlName = in.nextLine();\n    }\n    else\n    {\n      urlName = args&#x5B;0]; \/\/ Use first argument for hostname\n    }    \n    \n    URL url = new URL(urlName);\n    BufferedReader reader = new BufferedReader(\n      new InputStreamReader( url.openStream() ) \n    );\n    \n    try\n    {\n      String line = null;\n      while (true)\n      {\n        line = reader.readLine();\n        if (line == null)\n          break;\n        System.out.println(line);\n      }\n    }\n    finally\n    {\n      reader.close();\n    }\n  }\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">When I ran this on my machine, and entered the same URL I used in the previous program (chosen for its simplicity and brevity):<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"http:\/\/help.websiteos.com\/websiteos\/example_of_a_simple_html_page.htm\">http:\/\/help.websiteos.com\/websiteos\/example_of_a_simple_html_page.htm<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">it output the following:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>URL : http:\/\/help.websiteos.com\/websiteos\/example_of_a_simple_html_page.htm\n&lt;!doctype HTML public \"-\/\/W3C\/\/DTD HTML 4.0 Frameset\/\/EN\"&gt;\n\n&lt;!-- saved from url=(0014)about:internet --&gt;\n&lt;html&gt;\n\n&lt;head&gt;\n&lt;meta http-equiv=\"content-type\" content=\"text\/html;charset=windows-1252\"&gt;\n&lt;title&gt;Example of a simple HTML page&lt;\/title&gt;\n&lt;meta name=\"generator\" content=\"Adobe RoboHelp - www.adobe.com\"&gt;\n&lt;link rel=\"stylesheet\" href=\"default_ns.css\"&gt;&lt;script type=\"text\/javascript\" language=\"JavaScript\" title=\"WebHelpSplitCss\"&gt;\n&lt;!--\nif (navigator.appName !=\"Netscape\")\n{   document.write(\"&lt;link rel='stylesheet' href='default.css'&gt;\");}\n\/\/--&gt;\n&lt;\/script&gt;\n&lt;style type=\"text\/css\"&gt;\n&lt;!--\nimg_whs1 { border:none; width:301px; height:295px; float:none; }\np.whs2 { margin-bottom:5pt; }\np.whs3 { margin-bottom:9.5pt; }\n--&gt;\n\n...Lots of stuff omitted...\n\n&lt;\/body&gt;\n&lt;\/html&gt;<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Proxy_Settings\"><\/span>Proxy Settings<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">If you are using an HTTP proxy (for example if you are sitting behind a firewall) and need to access the URL through this proxy, then the following properties allow you to specify the proxy settings:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>http.proxyHost<\/strong>&nbsp;&#8212; the name of the proxy host<\/li><li><strong>http.proxyPort<\/strong>&nbsp;&#8212; the proxy host port number<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">If you are in a situation where you have to use a proxy server (most companies will probably require this), and fail to do this, then you will likely fail to read the URL properly.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s an example of the kind of code you&#8217;d write to set these system properties:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>    System.setProperty(\"http.proxyHost\", \"my-proxyhost.my-domain.com\");\n    System.setProperty(\"http.proxyPort\", \"89\");<\/strong><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>A&nbsp;<strong>proxy server<\/strong>&nbsp;is a&nbsp;server&nbsp;application or appliance that acts as an&nbsp;intermediary&nbsp;for requests from&nbsp;clients&nbsp;seeking resources from servers that provide those resources.&nbsp;A proxy server thus functions on behalf of the client when requesting service, potentially masking the true origin of the request to the resource server.<\/p><\/blockquote>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>Instead of connecting directly to a server that can fulfill a requested resource, such as a file or&nbsp;web page, the client directs the request to the proxy server, which evaluates the request and performs the required network transactions. This serves as a method to simplify or control the complexity of the request,&nbsp;or provide additional benefits such as load balancing, privacy, or security.&nbsp;<\/p><\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Sockets\"><\/span>Sockets<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">What&#8217;s a Socket?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When a client program wishes to connect to a host machine, on a specific port number, using TCP, it makes a connection request using a&nbsp;<em><strong>socket<\/strong><\/em>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A socket is a low-level communication mechanism on which other, higher level, protocols are based. Sockets are both&nbsp;<em>client-side<\/em>&nbsp;and&nbsp;<em>server-side<\/em>.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"The_Socket_Class\"><\/span>The Socket Class<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">The Socket class implements&nbsp;<em><strong>client sockets<\/strong><\/em>&nbsp;(also called just &#8220;sockets&#8221;).&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A&nbsp;<dfn>socket<\/dfn>&nbsp;is an endpoint for communication between two machines.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>For a lot more detail on the API for the Socket class click&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/docs.oracle.com\/javase\/1.5.0\/docs\/api\/java\/net\/Socket.html\" target=\"_blank\">here<\/a>.<\/p><\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s an example of how you can create a stream socket and connect it to the specified port number on the named host:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>Socket socket = new Socket(\"myhost.com\", socketNo);<\/strong><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The following:&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>Socket socket = new Socket(\"myhost.com\", socketNo, true);<\/strong><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">explicitly specifies that we should connect to a&nbsp;<em><strong>stream socket<\/strong><\/em>, whereas<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>Socket socket = new Socket(\"myhost.com\", socketNo, false);<\/strong><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">specifies that we should connect to a&nbsp;<em><strong>datagram socket<\/strong><\/em>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">There are corresponding constructors where the first argument is of type&nbsp;<strong>InetAddress<\/strong>, and there are other constructors with more complex sets of arguments.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Example\"><\/span>Example<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s a client program that reads from a specified socket on a specified host, and assumes that the results are simple text:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; auto-links: false; title: ; quick-code: false; notranslate\" title=\"\">\npackage networking;\n\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.IOException;\n\nimport java.net.Socket;\nimport java.util.Scanner;\n\n\/**\n *   Application to connect to a specified host and port\n *   and print the output text received from that connection.\n *\/\npublic class SocketTest\n{\n  \/**\n   * Main entry point\n   * \n   * @param args the command line arguments:\n   *             args&#x5B;0] : host name\n   *             args&#x5B;1] : port number\n   * \n   * If no command line arguments are provided, the program\n   * will prompt for them\n   *\/\n  public static void main(String&#x5B;] args)\n  {\n    String hostName = null;\n    int port = -1;\n    \n    if (args.length &lt; 2)\n    {\n      System.out.print(&quot;Hostname : &quot;);\n      Scanner in = new Scanner(System.in);\n      hostName = in.nextLine();\n      System.out.print(&quot;Port number : &quot;);\n      port = in.nextInt();\n    }\n    else\n    {\n      \/\/ First argument is hostname\n      hostName = args&#x5B;0];\n      \/\/ Convert port string to integer\n      port = Integer.parseInt(args&#x5B;1]);\n    }\n      \n    Socket socket = null;   \n    try\n    {\n      \/\/ Open the socket\n      socket = new Socket(hostName, port);\n      \/\/ Read from the socket\n      BufferedReader reader = new BufferedReader(\n                                    new InputStreamReader(\n                                        socket.getInputStream()\n                                    )\n                                );\n        \n      \/\/ Read line by line until the end\n      while (true)\n      {\n        String line = reader.readLine();\n        if (line == null)\n          break;  \/\/ We hit the end\n        System.out.println(line);\n      }\n    }\n    catch (NumberFormatException e)\n    {\n      System.err.println(&quot;Invalid port : &#x5B;&quot; + port +&quot;]&quot;);\n    }\n    catch (IOException e)\n    {\n      e.printStackTrace();\n    }\n  }\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">If you supply the following arguments to this program:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Hostname: <strong>time.nist.gov <\/strong>\nPort.     <strong>13<\/strong><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">(which is the time of day service running on a machine operated by the National Institute of Standards and Technology (NIST)) it will output the following:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>59252 21-02-07 20:41:21 00 0 0 789.5 UTC(NIST) * <\/strong><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">(or something similar).<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>UTC is Coordinated Universal Time.<\/p><p>This abbreviation comes as a result of the International Telecommunication Union and the International Astronomical Union wanting to use the same abbreviation in all languages. English speakers originally proposed <em>CUT<\/em> (for &#8220;coordinated universal time&#8221;), while French speakers proposed <em>TUC<\/em> (for &#8220;<em>temps universel coordonn\u00e9<\/em>&#8220;). The compromise that emerged was <em>UTC<\/em>.<\/p><\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Server_Sockets\"><\/span>Server Sockets<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">So far, we&#8217;ve just implemented client-side code. Let&#8217;s see what&#8217;s involved in implementing server-side code.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For simplicity, rather than using multiple machines over a network, we&#8217;ll just have the server and client run on the same machine.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"The_ServerSocket_Class\"><\/span>The ServerSocket Class<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">The&nbsp;ServerSocket&nbsp;class implements a&nbsp;<em><strong>server socket<\/strong><\/em>. A server socket waits for requests to come in over the network. It performs some operation based on that request, and then possibly returns a result to the requester.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For a lot more detail on the API for <strong>ServerSocket<\/strong>, click&nbsp;<a href=\"https:\/\/docs.oracle.com\/javase\/1.5.0\/docs\/api\/java\/net\/ServerSocket.html\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The&nbsp;<strong>ServerSocket<\/strong>&nbsp;class&#8217;s constructors expect a port number (the host is the machine on which the server program is running). It is also possible to specify a <em>backlog<\/em>, which allows you to restrict the queue size for connections. When the queue is full, the server socket refuses further connections until such time as the queue ceases to be full.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The most commonly used method in the&nbsp;<strong>ServerSocket<\/strong>&nbsp;class is probably&nbsp;<strong>accept()<\/strong>.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Server_Example\"><\/span>Server Example<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s a simple&nbsp;<strong>ReverseServer<\/strong> application, implemented using <strong>ServerSocket<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It simply accepts strings sent to it by its client, and returns the string with all the characters reversed.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; auto-links: false; title: ; quick-code: false; notranslate\" title=\"\">\npackage networking;\n\nimport java.net.ServerSocket;\nimport java.net.Socket;\n\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.io.PrintWriter;\nimport java.util.Scanner;\n\n\/**\n *   Application to act as a &#039;Reverse&#039; server.\n *   An application can connect to this server on the specified port\n *   and send it text.  The server will reverse the text and send it back.\n *\n *   @author Bryan J. Higgs, 10 October 1999\n *\/\npublic class ReverseServer\n{\n  \/**\n   *   Main entry point.\n   * \n   *   @param args the command line arguments\n   *               args&#x5B;0] contains port to use\n   * \n   * If there are no arguments, the program prompts for a port number\n   *\/\n  public static void main(String&#x5B;] args)\n  {\n    int port = -1;\n    \n    if (args.length &lt; 1)\n    {\n      System.out.print(&quot;Port to use: &quot;);\n      Scanner in = new Scanner(System.in);\n      port = in.nextInt();\n    }\n    else\n    {\n      port = Integer.parseInt(args&#x5B;0]);\n    }\n    \n    ServerSocket socket = null;\n    Socket incoming = null;\n    BufferedReader in = null;\n    PrintWriter out = null;\n    try\n    {\n      socket = new ServerSocket(port);\n      \/\/ Wait on server socket for connection requests\n      incoming = socket.accept();\n      \/\/ Connection requested; get the input stream\n      in = new BufferedReader(\n                new InputStreamReader(\n                    incoming.getInputStream()));\n      \/\/ Get the output stream\n      out = new PrintWriter(incoming.getOutputStream(),\n                            true        \/\/ autoflush\n                           );\n      \n      \/\/ Output greeting\n      out.println(\n          &quot;Welcome to the Reverse Server!&quot; +\n          &quot; Enter an empty line to exit.&quot;);\n      \n      \/\/ Loop, reversing each line received.\n      while (true)\n      {\n        String line = in.readLine();\n        if (line == null || line.equals(&quot;&quot;))\n          break; \/\/ We are at the end\n        \/\/ We read a line, so reverse it\n        StringBuffer buffer = new StringBuffer(line);\n        line = buffer.reverse().toString();\n        \/\/ and return the result\n        out.println(line);\n      }\n    }\n    catch (Exception e)\n    {\n      e.printStackTrace();\n    }\n    finally\n    {\n      \/\/ Close everything necessary\n      try\n      {\n        if (out != null)\n          out.close();\n        if (in != null)\n          in.close();\n        if (incoming != null)\n          incoming.close();\n        if (socket != null)\n          socket.close();\n      }\n      catch (IOException e)\n      {\n        \/\/ Ignore any errors here\n      }\n    }\n  }\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">So, you run it, and after giving it a port number, it sits there, seemingly doing nothing.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">That&#8217;s because it&#8217;s waiting for a client connection. So how to we connect to it? Here&#8217;s one way&#8230;<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Using_a_telnet_Client\"><\/span>Using a telnet Client<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">A simple way of testing our <strong>ReverseServer<\/strong> is to use a telnet client to connect to it.&nbsp; Unix\/Linux, Apple MacOS, and Windows all come with a telnet client.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can start the Windows Telnet client by clicking on the Windows Start menu&#8217;s Run&#8230; menu item, and entering &#8216;telnet&#8217; at the resulting prompt:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"alignleft size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"347\" height=\"186\" src=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-content\/uploads\/2021\/02\/UsingTelnet1.jpg\" alt=\"\" class=\"wp-image-463\" srcset=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-content\/uploads\/2021\/02\/UsingTelnet1.jpg 347w, https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-content\/uploads\/2021\/02\/UsingTelnet1-300x161.jpg 300w\" sizes=\"auto, (max-width: 347px) 100vw, 347px\" \/><\/figure><\/div>\n\n\n\n<div style=\"height:17px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">and clicking on the OK button.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This results in the telnet client coming up in a console window, where you will need to set the telnet client&#8217;s mode to local echo:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"alignleft size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"501\" height=\"331\" src=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-content\/uploads\/2021\/02\/UsingTelnet2.jpg\" alt=\"\" class=\"wp-image-464\" srcset=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-content\/uploads\/2021\/02\/UsingTelnet2.jpg 501w, https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-content\/uploads\/2021\/02\/UsingTelnet2-300x198.jpg 300w\" sizes=\"auto, (max-width: 501px) 100vw, 501px\" \/><\/figure><\/div>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Then you connect to the specified host and port using the&nbsp;<strong>open<\/strong>&nbsp;command.&nbsp; For example, for our <strong>ReverseServer<\/strong>, running on the local machine, and listening on port <strong>5000<\/strong>:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"alignleft size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"501\" height=\"331\" src=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-content\/uploads\/2021\/02\/UsingTelnet3.jpg\" alt=\"\" class=\"wp-image-465\" srcset=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-content\/uploads\/2021\/02\/UsingTelnet3.jpg 501w, https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-content\/uploads\/2021\/02\/UsingTelnet3-300x198.jpg 300w\" sizes=\"auto, (max-width: 501px) 100vw, 501px\" \/><\/figure><\/div>\n\n\n\n<div style=\"height:19px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">This command connects to the server, and the contents of the window changes to:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"alignleft size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"525\" height=\"331\" src=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-content\/uploads\/2021\/02\/UsingTelnet4.gif\" alt=\"\" class=\"wp-image-466\"\/><\/figure><\/div>\n\n\n\n<div style=\"height:21px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">As the previous window indicated, a&nbsp;<strong>Ctrl+]<\/strong>&nbsp;will allow you to return to the other mode.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now, you can interact with the <strong>ReverseServer<\/strong>:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"alignleft size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"525\" height=\"331\" src=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-content\/uploads\/2021\/02\/UsingTelnet5.gif\" alt=\"\" class=\"wp-image-467\"\/><\/figure><\/div>\n\n\n\n<div style=\"height:22px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Note that an empty line causes the <strong>ReverseServer<\/strong> to close down, which closes the connection.&nbsp; In other words, this version of the <strong>ReverseServer<\/strong> only handles a single client, and then exits &#8212; not too useful!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">On Unix\/Linux, you use a command window (aka Terminal on macOS) in a similar way. Here is what a macOS interaction looks like:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"alignleft size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"674\" src=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-content\/uploads\/2021\/02\/Screen-Shot-2021-02-07-at-4.25.37-PM-1024x674.png\" alt=\"\" class=\"wp-image-468\" srcset=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-content\/uploads\/2021\/02\/Screen-Shot-2021-02-07-at-4.25.37-PM-1024x674.png 1024w, https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-content\/uploads\/2021\/02\/Screen-Shot-2021-02-07-at-4.25.37-PM-300x197.png 300w, https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-content\/uploads\/2021\/02\/Screen-Shot-2021-02-07-at-4.25.37-PM-768x505.png 768w, https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-content\/uploads\/2021\/02\/Screen-Shot-2021-02-07-at-4.25.37-PM.png 1152w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n\n<div style=\"height:101px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"ReverseServer_Client_Example\"><\/span>ReverseServer Client Example<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s a simple Java client written to access&nbsp;<strong>ReverseServer<\/strong>:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; auto-links: false; title: ; quick-code: false; notranslate\" title=\"\">\npackage networking;\n\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\n\nimport java.net.Socket;\nimport java.net.UnknownHostException;\nimport java.util.Scanner;\n\n\/**\n *   Application to connect to a specified host and port\n *   and print the output text received from that connection.\n *\/\npublic class ReverseClient\n{\n  \/**\n   * Main entry point\n   * \n   * @param args the command line arguments:\n   *             args&#x5B;0] : host name\n   *             args&#x5B;1] : port number\n   * \n   * In the absence of arguments, the program will prompt for them\n   *\/\n  public static void main(String&#x5B;] args)\n  {\n    String hostName = null;\n    int port = -1;\n    \n    if (args.length &lt; 2)\n    {\n      System.out.print(&quot;Hostname : &quot;);\n      Scanner in = new Scanner(System.in);\n      hostName = in.nextLine();\n      System.out.print(&quot;Port number : &quot;);\n      port = in.nextInt();\n    }\n    else\n    {\n      \/\/ First argument is hostname\n      hostName = args&#x5B;0];\n      \/\/ Convert port string to integer\n      port = Integer.parseInt(args&#x5B;1]);\n    }\n    \n    \/\/ Connect a BufferedReader to System.in\n    BufferedReader inputReader = new BufferedReader(\n                     new InputStreamReader(System.in) );\n      \n    Socket socket;\n    try\n    {\n      socket = new Socket(hostName, port);\n        \n      \/\/ Connect a BufferedReader to read from the socket\n      BufferedReader socketReader = new BufferedReader(\n                       new InputStreamReader( socket.getInputStream() ) );\n        \n      \/\/ Connect a PrintWriter to write to the socket\n      PrintWriter socketWriter = new PrintWriter(\n            new OutputStreamWriter(socket.getOutputStream() ),\n            true \/\/ autoflush\n            );\n      \n      \/\/ Loop on input and server&#039;s response  \n      while (true)\n      {\n        \/\/ Read the reverse server&#039;s response\n        String line = socketReader.readLine();\n        if (line == null)\n          break;  \/\/ We hit the end\n        System.out.println(line);\n        \/\/ Prompt the user for another line\n        System.err.print(&quot;&gt; &quot;);\n        line = inputReader.readLine();\n        if (line == null)\n          line = &quot;&quot;;  \/\/ Send an empty line for end of input\n        socketWriter.println(line);\n      }\n    }\n    catch (UnknownHostException ex)\n    {\n      ex.printStackTrace();\n    }\n    catch (IOException ex)\n    {\n      ex.printStackTrace();\n    }\n  }\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">So, with the ReverseServer running on the localhost using port 5000, I ran this ReverseClient program, and here were the results:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Hostname : localhost\nPort number : 5000\nWelcome to the Reverse Server! Enter an empty line to exit.\n&gt; Hello!\n!olleH\n&gt; It's me, Bryan\nnayrB ,em s'tI\n&gt; Bye!\n!eyB\n&gt; <\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Multi-Threaded_Example\"><\/span>Multi-Threaded Example<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">You&#8217;ll note that the previous&nbsp;<strong>ReverseServer<\/strong>&nbsp;isn&#8217;t very friendly.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here are some of its problems:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>It accepts a single connection only<\/li><li>When the connection ends, it simply exits<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Not terribly useful!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">How can we do better? Use threads! <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s an example:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; auto-links: false; title: ; quick-code: false; notranslate\" title=\"\">\npackage networking;\n\nimport java.net.ServerSocket;\nimport java.net.Socket;\n\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.io.PrintWriter;\nimport java.util.Scanner;\n\n\/**\n *   Application to act as a Reverse server for multiple clients.\n *   An application can connect to this server on the specified port\n *   and send it text.  The server will reverse the text and send it back.\n *\n *   @author Bryan J. Higgs, 10 October 1999\n *\/\npublic class MultiThreadedReverseServer\n{\n  \/**\n   *   Main entry point.\n   * \n   *   @param args the command line arguments\n   *               args&#x5B;0] contains port to use\n   * \n   * If there are no arguments, the program prompts for a port number\n   *\/\n  public static void main(String&#x5B;] args)\n  {\n    int port = -1;\n    \n    if (args.length &lt; 1)\n    {\n      System.out.print(&quot;Port to use: &quot;);\n      Scanner in = new Scanner(System.in);\n      port = in.nextInt();\n    }\n    else\n    {\n      port = Integer.parseInt(args&#x5B;0]);\n    }\n    \n    ServerSocket socket = null;\n    Socket incoming = null;\n    int client = 0;\n    try\n    {\n      socket = new ServerSocket(port);\n      while (true)\n      {\n        \/\/ Wait on server socket for connection request\n        incoming = socket.accept();\n        \/\/ Create a handler thread for this request, and start it.\n        new ReverseHandler(incoming, ++client).start();\n      }\n    }\n    catch (Exception e)\n    {\n      e.printStackTrace();\n    }\n    finally\n    {\n      \/\/ Close the ServerSocket, regardless of success\n      try\n      {\n        if (socket != null)\n          socket.close();\n      }\n      catch (IOException e)\n      {\n        \/\/ Ignore any errors here\n      }\n    }\n  }\n}\n\n\/**\n *   Class to handle the connection request for a single client.\n *\/\nclass ReverseHandler extends Thread\n{\n  public ReverseHandler(Socket incoming, int client)\n  {\n    m_incoming = incoming;\n    m_client = client;\n    setName(&quot;ReverseHandler for client #&quot; + m_client);\n  }\n  \n  public void run()\n  {\n    BufferedReader in = null;\n    PrintWriter out = null;\n    \n    try\n    {\n      \/\/ Get the connection input stream\n      in = new BufferedReader(\n              new InputStreamReader(\n                  m_incoming.getInputStream() ) );\n      \/\/ Get the connection output stream\n      out = new PrintWriter(\n                  m_incoming.getOutputStream(),\n                  true        \/\/ autoflush\n                );\n      \n      \/\/ Output greeting to client\n      out.println(\n          &quot;Welcome to the Reverse Server!&quot; +\n          &quot; You are client #&quot; + m_client + &quot;.&quot; +\n          &quot; Enter an empty line to exit.&quot;);\n      \n      \/\/ Loop, reversing each line received.\n      while (true)\n      {\n        String line = in.readLine();\n        if (line == null || line.equals(&quot;&quot;))\n          break;\n        StringBuffer buffer = new StringBuffer(line);\n        line = buffer.reverse().toString();\n        out.println(line);\n      }\n    }\n    catch (Exception e)\n    {\n      e.printStackTrace();\n    }\n    finally\n    {\n      \/\/ Close everything necessary\n      try\n      {\n        if (out != null)\n          out.close();\n        if (in != null)\n          in.close();\n        if (m_incoming != null)\n          m_incoming.close();\n      }\n      catch (IOException e)\n      {\n        \/\/ Ignore any errors here\n      }\n    }\n  }\n  \n  \/\/\/\/ Private data \/\/\/\/\n  private Socket m_incoming;\n  private int    m_client;\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">We simply use threads to handle multiple simultaneous connections.&nbsp; The server looks exactly the same to its clients, except that it no longer goes away after the first connection ends.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s proof that it works:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"alignleft size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"668\" src=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-content\/uploads\/2021\/02\/Screen-Shot-2021-02-07-at-5.07.39-PM-1024x668.png\" alt=\"\" class=\"wp-image-473\" srcset=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-content\/uploads\/2021\/02\/Screen-Shot-2021-02-07-at-5.07.39-PM-1024x668.png 1024w, https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-content\/uploads\/2021\/02\/Screen-Shot-2021-02-07-at-5.07.39-PM-300x196.png 300w, https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-content\/uploads\/2021\/02\/Screen-Shot-2021-02-07-at-5.07.39-PM-768x501.png 768w, https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-content\/uploads\/2021\/02\/Screen-Shot-2021-02-07-at-5.07.39-PM.png 1150w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n\n<div style=\"height:29px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Ta-da!<\/p>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Web_Servers\"><\/span>Web Servers<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s focus our discussion for the moment on talking to a particular kind of server &#8212; a web server. That is, a server that implements HTTP (HyperText Transfer Protocol).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">More information about HTTP may be found at <a rel=\"noreferrer noopener\" href=\"http:\/\/www.w3.org\/Protocols\/\" target=\"_blank\">http:\/\/www.w3.org\/Protocols\/<\/a><\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"The_CGI\"><\/span>The CGI<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">The Common Gateway Interface (CGI) is a very common mechanism for communicating between a web browser and a web server. Typically, the steps are:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>The user fills in a form, which typically has input fields such as text fields, and lists, checkboxes, etc.<\/li><li>The user submits the data from the form, typically using a Submit button or similar mechanism<\/li><li>The web browser sends the data to the web server.<\/li><li>The web server sends the data to a CGI script.<\/li><li>The CGI script processes the form data and dynamically generates an HTML page<\/li><li>The web server passes the HTML page back to the browser<\/li><li>The web browser displays the HTML page, which are the results of the query.<\/li><\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">CGI scripts may be written in a number of different languages, including Java, perl, C, etc.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"CGI_Queries\"><\/span>CGI Queries<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Many web sites allow you use a&nbsp;<dfn>CGI query<\/dfn>.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A CGI query is:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>A regular URL, followed by<\/li><li>A question mark (?), followed by<\/li><li>A query string<\/li><\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">A query string is a set of name\/value pairs:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>name=value<\/strong><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">with each name\/value pair separated from the next with an ampersand (&amp;) character.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>http:\/\/www.google.com\/search?q=cgi+query&amp;sourceid=ie7&amp;rls=com.microsoft:en-US&amp;ie=utf8&amp;oe=utf8<\/strong><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">which comprises the following sets of name\/value pairs:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>q=cgi+query<\/strong><\/li><li><strong>sourceid=ie7<\/strong><\/li><li><strong>rls=com.microsoft:en-US<\/strong><\/li><li><strong>ie=utf8<\/strong><\/li><li><strong>oe=utf8<\/strong><\/li><\/ul>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Google_Maps_Example\"><\/span>Google Maps Example<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s an example. It performs a CGI query against Google Maps:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; auto-links: false; title: ; quick-code: false; notranslate\" title=\"\">\npackage networking;\n\nimport java.awt.BorderLayout;\nimport java.awt.EventQueue;\nimport java.awt.Font;\nimport java.awt.event.ActionEvent;\nimport java.awt.event.ActionListener;\n\nimport java.net.URL;\nimport java.net.MalformedURLException;\n\nimport java.util.Properties;\n\nimport javax.swing.JButton;\nimport javax.swing.JEditorPane;\nimport javax.swing.JFrame;\nimport javax.swing.JPanel;\nimport javax.swing.JScrollPane;\nimport static javax.swing.WindowConstants.EXIT_ON_CLOSE;\n\n\/**\n *   Program to perform a query against Google Maps.\n *\/\npublic class CGIQueryMapsExample extends JFrame\n{\n  \/** \n   * Main entry point\n   * \n   * @param args \n   *\/\n  public static void main(String&#x5B;] args)\n  {\n    EventQueue.invokeLater( new Runnable()\n      {\n        public void run()\n        {\n          CGIQueryMapsExample frame = new CGIQueryMapsExample();\n          frame.setDefaultLookAndFeelDecorated(true);\n          frame.setDefaultCloseOperation(EXIT_ON_CLOSE);\n          frame.setTitle(&quot;CGI Query Google Maps&quot;);\n          frame.setBounds(200, 200, 800, 500);\n          frame.setVisible(true);\n        }\n      }\n    );\n\n  }  \n  \n  \/**\n   * Constructor\n   *\/\n  public CGIQueryMapsExample()\n  {\n    JPanel contentPane = (JPanel) getContentPane();\n    contentPane.setLayout( new BorderLayout() );\n    contentPane.add(m_button, BorderLayout.SOUTH);\n    contentPane.add(m_browserButton, BorderLayout.NORTH);\n    \n    \/\/ Set attributes of the buttons\n    m_button.setFont( new Font(&quot;SansSerif&quot;, Font.PLAIN, 14) );\n    m_browserButton.setFont( new Font(&quot;SansSerif&quot;, Font.PLAIN, 14) );\n    m_browserButton.setEnabled(false); \/\/ Disabled until query done\n    \n    JScrollPane scrollPane = new JScrollPane();\n    m_editorPane = new JEditorPane();\n    m_editorPane.setEditable(false);\n    scrollPane.setViewportView(m_editorPane);\n    contentPane.add(scrollPane, BorderLayout.CENTER);\n    \n    m_button.addActionListener( new ActionListener()\n    {\n      public void actionPerformed(ActionEvent e)\n      {\n        \/\/ Postpone the work to perform the query\n        EventQueue.invokeLater(new Runnable()\n        {\n          public void run()\n          {\n            performQuery();\n          }\n        }\n        );\n      }\n    }\n    );\n    \n    m_browserButton.addActionListener( new ActionListener()\n    {\n      public void actionPerformed(ActionEvent e)\n      {\n        if (m_url != null)\n        {\n          BareBonesBrowserLaunch.openURL(m_url.toString());\n        }\n      }\n    }\n    );\n  }\n  \n  \/**\n   *   Perform the query, firing up a new browser window.\n   *\/\n  private void performQuery()\n  {\n    try\n    {\n      \/\/ Create the base URL\n      URL url = new URL(&quot;http:\/\/maps.google.com\/maps&quot;);\n      \n      \/\/ Create the set of properties needed for the query\n      Properties props = new Properties();\n      props.put(&quot;f&quot;, &quot;q&quot;);\n      props.put(&quot;hl&quot;, &quot;en&quot;);\n      props.put(&quot;q&quot;, &quot;Eiffel Tower, Paris France&quot;);\n      props.put(&quot;ie&quot;, &quot;UTF8&quot;);\n      props.put(&quot;z&quot;, &quot;12&quot;);\n      props.put(&quot;om&quot;, &quot;1&quot;);\n      try\n      {\n        \/\/ Create the final query URL\n        url = URLQuery.createQuery(url, props);\nSystem.out.println(&quot;Showing document: &quot; + url);\n        \/\/ Open the URL in the editor pane\n        m_editorPane.setPage(url);\n        \/\/ Now we succeeded, set the class instance url field\n        \/\/ and enable the browser button\n        m_url = url;\n        m_browserButton.setEnabled(true);\n      } \n      catch (Exception ex)\n      {\n        ex.printStackTrace();\n      } \n    }\n    catch (MalformedURLException e)\n    {\n      e.printStackTrace();\n    }\n  }\n  \n  \/\/\/\/ Private data \/\/\/\/\n  private JEditorPane m_editorPane = null;\n  private URL m_url = null;\n  private JButton m_button = new JButton(&quot;Google Maps Query&quot;);\n  private JButton m_browserButton = new JButton(&quot;Try it in a browser window&quot;);\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">The above program makes use of a useful class&nbsp;<strong>URLQuery<\/strong>&nbsp;, which allows convenient construction of a query URL from a base URL and a set of properties:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; auto-links: false; title: ; quick-code: false; notranslate\" title=\"\">\npackage networking;\n\nimport java.io.UnsupportedEncodingException;\nimport java.net.URL;\nimport java.net.URLEncoder;\nimport java.net.MalformedURLException;\n\nimport java.util.Enumeration;\nimport java.util.Properties;\n\n\/**\n *   Class to create a URL to perform a CGI query against a web server.\n *\/\npublic class URLQuery\n{\n  \/**\n   *   Creates a URL query from the base URL and the set of properties.\n   *\/\n  public static URL createQuery(URL baseURL, Properties params)\n      throws MalformedURLException, UnsupportedEncodingException\n  {\n    \/\/ Queries use the URL followed by a &#039;?&#039; character\n    String file = baseURL.getFile() + &quot;?&quot;;\n    \n    \/\/ And then append the query parameters to the URL string\n    Enumeration e = params.propertyNames();\n    int count = 0;\n    while ( e.hasMoreElements() )\n    {\n      String propertyName = (String) e.nextElement();\n      propertyName = URLEncoder.encode(propertyName, &quot;UTF-8&quot;);\n      if (count &gt; 0)\n        file += &quot;&amp;&quot;;        \/\/ Separate parameters with &#039;&amp;&#039; character\n      file += propertyName;\n      String propertyValue = params.getProperty(propertyName);\n      if (propertyValue != null)\n      {\n        propertyValue = URLEncoder.encode(propertyValue, &quot;UTF-8&quot;);\n        file += &quot;=&quot; + propertyValue;\n      }\n      count++;\n    }\n    \n    return new URL(baseURL.getProtocol(), \n                   baseURL.getHost(),\n                   baseURL.getPort(), \n                   file);\n  }\n  \n  \/**\n   * Constructor disabled by making it private\n   *\/\n  private URLQuery()\n  {\n  }\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">When I ran this program, here&#8217;s what it produced:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"alignleft size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"644\" src=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-content\/uploads\/2021\/02\/Screen-Shot-2021-02-08-at-5.11.40-PM-1024x644.png\" alt=\"\" class=\"wp-image-476\" srcset=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-content\/uploads\/2021\/02\/Screen-Shot-2021-02-08-at-5.11.40-PM-1024x644.png 1024w, https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-content\/uploads\/2021\/02\/Screen-Shot-2021-02-08-at-5.11.40-PM-300x189.png 300w, https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-content\/uploads\/2021\/02\/Screen-Shot-2021-02-08-at-5.11.40-PM-768x483.png 768w, https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-content\/uploads\/2021\/02\/Screen-Shot-2021-02-08-at-5.11.40-PM-1536x965.png 1536w, https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-content\/uploads\/2021\/02\/Screen-Shot-2021-02-08-at-5.11.40-PM.png 1610w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n\n<div style=\"height:15px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">And when I clicked on the Google Maps Query button (at the bottom), after a slight delay, it showed the following:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"alignleft size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"645\" src=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-content\/uploads\/2021\/02\/Screen-Shot-2021-02-08-at-5.12.08-PM-1024x645.png\" alt=\"\" class=\"wp-image-477\" srcset=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-content\/uploads\/2021\/02\/Screen-Shot-2021-02-08-at-5.12.08-PM-1024x645.png 1024w, https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-content\/uploads\/2021\/02\/Screen-Shot-2021-02-08-at-5.12.08-PM-300x189.png 300w, https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-content\/uploads\/2021\/02\/Screen-Shot-2021-02-08-at-5.12.08-PM-768x484.png 768w, https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-content\/uploads\/2021\/02\/Screen-Shot-2021-02-08-at-5.12.08-PM-1536x967.png 1536w, https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-content\/uploads\/2021\/02\/Screen-Shot-2021-02-08-at-5.12.08-PM.png 1610w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n\n<div style=\"height:17px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Google appears to have a rather original way of telling you that it needs JavaScript to show the results. (That is true of a large number of websites, today.)<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>Notice the button at the top of the window: &#8220;Try it in a browser window&#8221;. This button is initially disabled. However, once we have completed our CGI query, and displayed the &#8220;results&#8221; in the program, it is now enabled, and allows you to click on it. When I clicked on it, it fired up a browser page using the constructed URL, and correctly displays the Google Map results.<\/p><p>If you want to try it yourself, you&#8217;ll need a very useful class BareBonesBrowserLaunch, which you can find at <a rel=\"noreferrer noopener\" href=\"https:\/\/centerkey.com\/java\/browser\/\" target=\"_blank\">https:\/\/centerkey.com\/java\/browser\/<\/a> . You&#8217;ll have to change its package name to <strong>networking<\/strong> in order to use it with this application.<\/p><\/blockquote>\n\n\n\n<div style=\"height:41px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"The_CGI_GET_POST_Methods\"><\/span>The CGI GET &amp; POST Methods<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">There are two basic methods for performing CGI queries:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>GET, and<\/li><li>POST<\/li><\/ul>\n\n\n\n<h5 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"The_CGI_GET_Method\"><\/span>The CGI GET Method<span class=\"ez-toc-section-end\"><\/span><\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">The protocol for an HTTP GET method is for the client to send the following string to the web server:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>GET <\/strong><em><strong>scriptname?parameters<\/strong><\/em><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">followed by a blank line.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"The_CGI_POST_Method\"><\/span>The CGI POST Method<span class=\"ez-toc-section-end\"><\/span><\/h5>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>Coverage of the CGI POST Method is beyond the scope of this topic. Suffice it to say that, with a GET Method, the data is passed within the URL. In a POST Method, the data is passed separately in the message sent to the browser, or returned from the browser.<\/p><\/blockquote>\n\n\n\n<h5 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"The_URLConnection_class\"><\/span>The&nbsp;URLConnection&nbsp;class<span class=\"ez-toc-section-end\"><\/span><\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">Another approach is to use an HTTP-oriented class called&nbsp;URLConnection.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The abstract class&nbsp;URLConnection&nbsp;is the superclass of all classes that represent a communications link between the application and a URL. Instances of this class can be used both to read from and to write to the resource referenced by the URL.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In general, creating a connection to a URL is a multistep process:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td class=\"has-text-align-left\" data-align=\"left\"><strong>openConnection()<\/strong><\/td><td><strong>connect()<\/strong><\/td><\/tr><tr><td class=\"has-text-align-left\" data-align=\"left\">Manipulate parameters that affect the connection to the remote resource.<\/td><td>Interact with the resource; query header fields and contents<\/td><\/tr><tr><td class=\"has-text-align-right\" data-align=\"right\"><strong>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-&gt;<\/strong><\/td><td>&nbsp;<\/td><\/tr><tr><td class=\"has-text-align-right\" data-align=\"right\"><em><strong>time<\/strong><\/em><\/td><td>&nbsp;<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<ol class=\"wp-block-list\"><li>The connection object is created by invoking the&nbsp;openConnection&nbsp;method on a URL.<\/li><li>The setup parameters and general request properties are manipulated.<\/li><li>The actual connection to the remote object is made, using the&nbsp;connect&nbsp;method.<\/li><li>The remote object becomes available. The header fields and the contents of the remote object can be accessed.<\/li><\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">The setup parameters are modified using the following methods:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>setAllowUserInteraction<\/li><li>setDoInput<\/li><li>setDoOutput<\/li><li>setIfModifiedSince<\/li><li>setUseCaches<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">and the general request properties are modified using the method:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>setRequestProperty<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Default values for the&nbsp;AllowUserInteraction&nbsp;and&nbsp;UseCaches&nbsp;parameters can be set using the methods&nbsp;setDefaultAllowUserInteraction&nbsp;and setDefaultUseCaches. Default values for general request properties can be set using the&nbsp;setDefaultRequestProperty&nbsp;method.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Each of the above set methods has a corresponding get method to retrieve the value of the parameter or general request property. The specific parameters and general request properties that are applicable are protocol specific.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The following methods are used to access the header fields and the contents after the connection is made to the remote object:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>getContent<\/li><li>getHeaderField<\/li><li>getInputStream<\/li><li>getOutputStream<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Certain header fields are accessed frequently. The methods:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>getContentEncoding<\/li><li>getContentLength<\/li><li>getContentType<\/li><li>getDate<\/li><li>getExpiration<\/li><li>getLastModified<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">provide convenient access to these fields. The&nbsp;getContentType&nbsp;method is used by the&nbsp;getContent&nbsp;method to determine the type of the remote object; subclasses may find it convenient to override the&nbsp;getContentType&nbsp;method.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In the common case, all of the pre-connection parameters and general request properties can be ignored: the pre-connection parameters and request properties default to sensible values. For most clients of this interface, there are only two interesting methods:&nbsp;getInputStream&nbsp;and&nbsp;getObject, which are mirrored in the&nbsp;URL&nbsp;class by convenience methods.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-style-default is-layout-flow wp-block-quote-is-layout-flow\"><p><strong><em><u>Note about&nbsp;fileNameMap:<\/u><\/em><\/strong>&nbsp;In versions prior to JDK 1.1.6, field fileNameMap&nbsp;of&nbsp;URLConnection&nbsp;was&nbsp;public. In JDK 1.1.6 and later,&nbsp;fileNameMap&nbsp;is&nbsp;private; accessor method&nbsp;getFileNameMap()&nbsp;and mutator method&nbsp;setFileNameMap(FileNameMap)&nbsp;are added to access it. This change is also described on the JDK 1.1.x Compatibility page.<\/p><\/blockquote>\n\n\n\n<h5 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Reading_from_a_URL_using_URLConnection\"><\/span>Reading from a URL using&nbsp;URLConnection<span class=\"ez-toc-section-end\"><\/span><\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s the equivalent to the&nbsp;<a href=\"#reading-from-a-url\">URLReader&nbsp;program<\/a>&nbsp;we developed earlier, but using a&nbsp;<strong>URLConnection<\/strong>:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; auto-links: false; title: ; quick-code: false; notranslate\" title=\"\">\npackage networking;\n\nimport java.net.URL;\nimport java.net.URLConnection;\n\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.Scanner;\n\n\/**\n*   Application to read text from a URL specified in the \n*   first command line argument, using a URLConnection\n*   (Note that this is NOT a Reader in the same sense as BufferedReader.)\n*\/\npublic class URLConnectionReader\n{\n  \/**\n   * Main entry point\n   * \n   * @usage java networking.NodeLookup urlstring\n   * \n   * If no arguments provided, will prompt for urlstring\n   * \n   * @param args the command line arguments\n   *             args&#x5B;0] contains the urlstring to read\n   *\/\n   public static void main(String&#x5B;] args) throws Exception\n   {\n     String urlName;\n    \n     if (args.length &lt; 1)\n     {\n       System.out.print(&quot;URL : &quot;);\n       Scanner in = new Scanner(System.in);\n       urlName = in.nextLine();\n     }\n     else\n     {\n       urlName = args&#x5B;0]; \/\/ Use first argument for hostname\n     }    \n        \n     URL url = new URL(urlName);\n     URLConnection conn = url.openConnection();\n     BufferedReader reader = new BufferedReader(\n                                        new InputStreamReader(\n                                                conn.getInputStream()));\n     try\n     {\n        String line = null;\n        while (true)\n        {\n          line = reader.readLine();\n          if (line == null)\n            break;\n          System.out.println(line);\n        }\n     }\n     finally\n     {\n        reader.close();\n     }\n   }\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">When I ran it, using the same webpage URL as I used with the previous program, it gave me the same results.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Writing_to_a_URL_using_URLConnection\"><\/span>Writing to a URL using&nbsp;URLConnection<span class=\"ez-toc-section-end\"><\/span><\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">For the HTTP protocol, writing to a URL means using CGI (Common Gateway Interface) scripts on the server.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Many CGI scripts use the POST METHOD for reading the data from the client &#8212; hence the term&nbsp;<em>posting to a URL<\/em>. Server-side scripts use the POST METHOD to read from their standard input.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The following program uses a CGI script available at&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">http:\/\/java.sun.com\/cgi-bin\/reverse&nbsp;<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">or <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">http:\/\/java.sun.com\/cgi-bin\/backwards<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The script reverses any string supplied to it.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>Unfortunately, somewhere in the transfer of Java from Sun Microsystems to Oracle, this reverse server seems to have disappeared. I&#8217;ll try to find an alternative&#8230;<\/p><\/blockquote>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\npackage networking;\n\nimport java.net.URL;\nimport java.net.URLConnection;\nimport java.net.URLEncoder;\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.net.MalformedURLException;\nimport java.nio.charset.Charset;\nimport java.util.Scanner;\n\npublic class ReverseCGIClient\n{\n    \/**\n    * Main entry point\n    * \n    * @usage java networking.ReverseCGIClient string-to-reverse&gt;\n    * \n    * @param args\n    * \n    *\/\n    public static void main(String&#x5B;] args)\n    {\n        String reverseMe;\n\n        if (args.length &amp;lt; 1)\n        {\n        System.out.print(&quot;String to reverse : &quot;);\n        Scanner in = new Scanner(System.in);\n        reverseMe = in.nextLine();\n        }\n        else\n        {\n        reverseMe = args&#x5B;0]; \/\/ Use first argument for string to reverse\n        }    \n\n        \/\/ Translate into x-www-form-urlencoded format:\n        reverseMe = URLEncoder.encode(reverseMe, Charset.defaultCharset());\n        \n        URLConnection conn = null;\n        PrintWriter out = null;\n        BufferedReader in = null;\n        \n        try\n        {\n            \/\/ Open connection to URL\n            System.err.println(&quot;Accessing URL&quot;);\n            URL url = new URL(&quot;http:\/\/java.sun.com\/cgi-bin\/backwards&quot;);\n            System.err.println(&quot;Opening URL connection&quot;);\n            conn = url.openConnection();\n            \/\/ Set connection so it can do output\n            conn.setDoOutput(true);\n            \n            \/\/ Provide input to server using the output stream.\n            out = new PrintWriter(conn.getOutputStream());\n            \n            out.println(&quot;string=&quot; + reverseMe);\n            \n            \/\/ Read response from server\n            in = new BufferedReader( new InputStreamReader(\n                                            conn.getInputStream()));\n            String line = null;\n            while (true)\n            {\n                line = in.readLine();\n                if (line == null)\n                    break;\n                System.out.println(line);\n            }\n        }\n        catch (MalformedURLException ex)\n        {\n            ex.printStackTrace();\n        }\n        catch (IOException ex)\n        {\n            ex.printStackTrace();\n        }\n        finally\n        {\n            out.close();\n            try\n            {\n                in.close();\n            }\n            catch (IOException ex)\n            {\n                ex.printStackTrace();\n            }\n        }\n    }\n}\n<\/pre><\/div>\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h5 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"GET_POST\"><\/span>GET &amp; POST<span class=\"ez-toc-section-end\"><\/span><\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">There are two basic methods for performing CGI queries:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>GET<\/strong>, and<\/li><li><strong>POST<\/strong><\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">(Actually, there are a number of additional methods, but we will ignore these others for the purposes of this discussion.)<\/p>\n\n\n\n<h6 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"The_CGI_GET_Method-2\"><\/span>The CGI GET Method<span class=\"ez-toc-section-end\"><\/span><\/h6>\n\n\n\n<p class=\"wp-block-paragraph\">The protocol for an HTTP GET method is for the client to send a request message to the web server that looks something like:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">GET \/images\/logo.gif HTTP\/1.1\nAccept: image\/gif, image\/x-xbitmap, image\/jpeg, image\/pjpeg, *\/*\nAccept-Language: en-us\nAccept-Encoding: gzip, deflate\nUser-Agent: Mozilla\/4.0 (compatible; MSIE 5.01; Windows NT)\nHost: www.rivier.edu\nConnection: Keep-Alive<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">followed by a blank line.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In the above GET request message, the first line requests a file&nbsp;<strong>logo.gif<\/strong>&nbsp;from the web server.&nbsp; The file is expected to be located in the&nbsp;images&nbsp;folder.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If any CGI query string is present, it is appended to the URL in the first line.&nbsp; Problems with this include:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>The entire URL is usually displayed in the Address field of the browser, so any sensitive information (such as passwords) are too visible.<\/li><li>Every browser (and probably every web server) has some upper limit on the size of a URL, including any query string, so there is a limit on how much data can be passed using this method.<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">The lines following the first line, and preceding the blank line are&nbsp;<dfn>Request Headers<\/dfn>&nbsp;(one request header per line).<\/p>\n\n\n\n<h6 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"The_CGI_POST_Method-2\"><\/span>The CGI POST Method<span class=\"ez-toc-section-end\"><\/span><\/h6>\n\n\n\n<p class=\"wp-block-paragraph\">The POST method attempts to solve these problems by moving the name\/value pairs that comprise the query string into the main body of the request message:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">POST \/cg-bin\/queryProcessor HTTP\/1.1\nAccept: image\/gif, image\/x-xbitmap, image\/jpeg, image\/pjpeg, *\/*\nAccept-Language: en-us\nAccept-Encoding: gzip, deflate\nUser-Agent: Mozilla\/4.0 (compatible; MSIE 5.01; Windows NT)\nHost: www.rivier.edu\nConnection: Keep-Alive\n\nname=Bryan\ncollege=Rivier\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Which allows larger amounts of data to be passed in the message.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The data inside the message is also not displayed in the browser&#8217;s address field.<\/p>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Extended_Example\"><\/span>Extended Example<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s a more extended example of the use of&nbsp;URLConnection.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To learn more about Basic Authorization in HTTP, you can go to:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"http:\/\/www.w3.org\/Protocols\/rfc2616\/rfc2616.html\" target=\"_blank\" rel=\"noreferrer noopener\">RFC 2616, Hypertext Transfer Protocol &#8212; HTTP\/1.1<\/a><\/li><li><a href=\"http:\/\/www.ietf.org\/rfc\/rfc2617.txt\" target=\"_blank\" rel=\"noreferrer noopener\">RFC 2617, HTTP Authentication: Basic and Digest Access Authentication<\/a><\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">The passing of Basic Authorization credentials (username and password) involves Base64 encoding.&nbsp;&nbsp;<br>You can learn more about Base64 encoding at <a rel=\"noreferrer noopener\" href=\"http:\/\/en.wikipedia.org\/wiki\/Base64\" target=\"_blank\">http:\/\/en.wikipedia.org\/wiki\/Base64<\/a>&nbsp;.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; auto-links: false; title: ; quick-code: false; notranslate\" title=\"\">\npackage networking;\n\nimport java.io.ByteArrayOutputStream;\nimport java.io.IOException;\nimport java.net.MalformedURLException;\nimport java.net.URL;\nimport java.net.URLConnection;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.Scanner;\n\n\/**\n * Class to connect to a URL and display the response header \n * data and first ten lines of the the requested data.\n *\n * (Based on the class supplied in Core Java 2, Vol II,\n *  Advanced Concepts, by Horstmann &amp; Cornell, Prentice-Hall, 2005)\n *\/\npublic class URLConnectionTest\n{\n  \/**\n   * Main entry point\n   * @param args the command line arguments\n   *             args&#x5B;0] contains the URL \n   *             args&#x5B;1] &amp; args&#x5B;2] contain an optional\n   *                     username and password.\n   *\/\n  public static void main(String&#x5B;] args)\n  {\n    String urlString = null;\n    String username = null;\n    String password = null;\n    \n    if (args.length &gt; 0)\n    {\n      urlString = args&#x5B;0];\n      \n      if (args.length &gt; 1)\n      {\n        username = args&#x5B;1];\n        \n        if (args.length &gt; 2)\n        {\n          password = args&#x5B;2];\n        }\n      }\n    }\n    else\n    {\n      \/\/ No arguments supplied, so prompt for them\n      Scanner in = new Scanner(System.in);\n      System.out.print(&quot;URL : &quot;);\n      urlString = in.nextLine();\n      System.out.print(&quot;Username (optional) : &quot;);\n      username = in.nextLine();\n      if (username.isBlank())\n        username = null;\n      System.out.print(&quot;Password (optional) : &quot;);\n      password = in.nextLine();\n      if (password.isBlank())\n        password = null;\n    }\n    \n    try\n    {\n        URL url = new URL(urlString);\n        URLConnection connection = url.openConnection();\n\n        if (username != null)\n        {\n          String input = username + &quot;:&quot; + password;\n          String encoding = base64Encode(input);\n          connection.setRequestProperty(&quot;Authorization&quot;, &quot;Basic &quot; + encoding);\n        }\n\n        System.out.println(&quot;&gt;&gt;&gt;&gt;&quot;);\n        System.out.println(&quot;Connecting to: &quot; + urlString);\n\n        connection.connect();\n\n        System.out.println(&quot;Connected...&quot;);\n\n        \/\/ Print the Method line\n        System.out.println(&quot;----------Method--------------&quot;);\n        System.out.println(&quot;&#x5B;0] &quot; + connection.getHeaderField(0));\n\n        \/\/ Print header fields\n        System.out.println(&quot;----------Response Headers----&quot;);\n        for (int line = 1; ; line++)\n        {\n          String header = connection.getHeaderField(line);\n          if (header == null)\n            break;\n          System.out.println(&quot;&#x5B;&quot; + line + &quot;] &quot; + \n                               connection.getHeaderFieldKey(line) + &quot;: &quot; +\n                               header\n                              );\n        }\n\n        \/\/ Print how many header lines (subtract one for the 0th entry, \n        \/\/ which is the Method line).\n        Map&lt;String, List&lt;String&gt;&gt; headers = connection.getHeaderFields();\n        System.out.println(&quot;There were &quot; + (headers.size() - 1) + &quot; header lines&quot;);\n\n        \/\/ Print convenience function outputs\n\n        System.out.println(&quot;----------Convenience functions----&quot;);\n        System.out.println(&quot;getContentType: &quot; + connection.getContentType());\n        System.out.println(&quot;getContentLength: &quot; + connection.getContentLength());\n        System.out.println(&quot;getContentEncoding: &quot; + connection.getContentEncoding());\n        System.out.println(&quot;getDate: &quot; + connection.getDate());\n        System.out.println(&quot;getExpiration: &quot; + connection.getExpiration());\n        System.out.println(&quot;getLastModified: &quot; + connection.getLastModified());\n\n        Scanner in = new Scanner(connection.getInputStream());\n\n        \/\/ Print first ten lines of contents \n\n        System.out.println(&quot;----------Content--------&quot;);\n        for (int line = 1; in.hasNextLine() &amp;&amp; line &lt;= 10; line++)\n        {\n          System.out.println(&quot;&#x5B;&quot; + line + &quot;] &quot; + in.nextLine());\n        }\n        if (in.hasNextLine())\n        {\n          System.out.println(&quot;. . .&quot;);\n        }\n    }\n    catch (MalformedURLException ex)\n    {\n        ex.printStackTrace();\n    }\n    catch (IOException ex)\n    {\n        ex.printStackTrace();\n    }\n  }\n\n  \/**\n   * Computes the Base64 encoding of a string\n   * @param string the string\n   * @return the Base64 encoding of string\n   *\/\n  public static String base64Encode(String string)\n  {\n    ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();\n    Base64OutputStream out = new Base64OutputStream(bytesOut);\n    try\n    {\n      out.write(string.getBytes());\n      out.flush();\n    }\n    catch (IOException ioe)\n    {\n      \/\/ Do nothing\n    }\n    return bytesOut.toString();\n  }\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">This uses a class to perform the necessary Base64 encoding:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; auto-links: false; title: ; quick-code: false; notranslate\" title=\"\">\npackage networking;\n\nimport java.io.FilterOutputStream;\nimport java.io.IOException;\nimport java.io.OutputStream;\n\n\/**\n * This class implements a stream filter that converts\n * a stream of bytes to their Base64 encoding.\n *\n * Base64 encoding encodes 3 bytes into 4 characters.\n * |11111122|22223333|444444|\n * Each set of 6 bits is encoded according to the m_toBase64 map.\n * If the number of input bytes is not a multiple of 3, then the \n * last group of characters is padded with one or two = signs.\n * Each output line is at most 76 characters.\n *\n * (Based on the class supplied in Core Java 2, Vol II,\n *  Advanced Concepts, by Horstmann &amp; Cornell, Prentice-Hall, 2005)\n *\/\npublic class Base64OutputStream extends FilterOutputStream\n{\n  \/**\n   * Constructor\n   * @param out the stream to filter\n   *\/\n  public Base64OutputStream(OutputStream out)\n  {\n    super(out);\n  }\n  \n  \/**\n   * Writes the specified &lt;code&gt;byte&lt;\/code&gt; to this output stream. \n   * &lt;p&gt;\n   * @param      c the &lt;code&gt;byte&lt;\/code&gt;.\n   *\/\n  public void write(int c) throws IOException\n  {\n    m_inbuf&#x5B;m_i] = c;\n    m_i++;\n    if (m_i == 3)\n    {\n      super.write( m_toBase64&#x5B;(m_inbuf&#x5B;0] &amp; 0xFC) &gt;&gt; 2] );\n      super.write( m_toBase64&#x5B;((m_inbuf&#x5B;0] &amp; 0x03) &lt;&lt; 4) |\n                              ((m_inbuf&#x5B;1] &amp; 0xF0) &gt;&gt; 4)] );\n      super.write( m_toBase64&#x5B;((m_inbuf&#x5B;1] &amp; 0x0F) &lt;&lt; 2) |\n                              ((m_inbuf&#x5B;2] &amp; 0xC0) &gt;&gt; 6)] );\n      super.write( m_toBase64&#x5B;m_inbuf&#x5B;2] &amp; 0x3F] );\n      m_col += 4;\n      m_i = 0;\n      if (m_col &gt;= 76)\n      {\n        super.write(&#039;\\n&#039;);\n        m_col = 0;\n      }\n    }\n  }\n  \n  \/**\n   * Flushes this output stream and forces any buffered output bytes \n   * to be written out to the stream. \n   *\/\n  public void flush() throws IOException\n  {\n    if (m_i == 1)\n    {\n      super.write( m_toBase64&#x5B;(m_inbuf&#x5B;0] &amp; 0xFC) &gt;&gt; 2] );\n      super.write( m_toBase64&#x5B;(m_inbuf&#x5B;0] &amp; 0x03) &lt;&lt; 4] );\n      super.write(&#039;=&#039;);\n      super.write(&#039;=&#039;);\n    }\n    else if (m_i == 2)\n    {\n      super.write( m_toBase64&#x5B;(m_inbuf&#x5B;0] &amp; 0xFC) &gt;&gt; 2] );\n      super.write( m_toBase64&#x5B;((m_inbuf&#x5B;0] &amp; 0x03) &lt;&lt; 4) |\n                              ((m_inbuf&#x5B;1] &amp; 0xF0) &gt;&gt; 4)] );\n      super.write( m_toBase64&#x5B;(m_inbuf&#x5B;1] &amp; 0x0F) &lt;&lt; 2] );\n      super.write(&#039;=&#039;);\n    }\n  }\n  \n  \/\/\/\/\/\/\/ Private data \/\/\/\/\/\/\/\/\/\n  private static char&#x5B;] m_toBase64 =\n  {\n    &#039;A&#039;, &#039;B&#039;, &#039;C&#039;, &#039;D&#039;, &#039;E&#039;, &#039;F&#039;, &#039;G&#039;, &#039;H&#039;, &#039;I&#039;, &#039;J&#039;, \n    &#039;K&#039;, &#039;L&#039;, &#039;M&#039;, &#039;N&#039;, &#039;O&#039;, &#039;P&#039;, &#039;Q&#039;, &#039;R&#039;, &#039;S&#039;, &#039;T&#039;,\n    &#039;U&#039;, &#039;V&#039;, &#039;W&#039;, &#039;X&#039;, &#039;Y&#039;, &#039;Z&#039;,\n    &#039;a&#039;, &#039;b&#039;, &#039;c&#039;, &#039;d&#039;, &#039;e&#039;, &#039;f&#039;, &#039;g&#039;, &#039;h&#039;, &#039;i&#039;, &#039;j&#039;, \n    &#039;k&#039;, &#039;l&#039;, &#039;m&#039;, &#039;n&#039;, &#039;o&#039;, &#039;p&#039;, &#039;q&#039;, &#039;r&#039;, &#039;s&#039;, &#039;t&#039;,\n    &#039;u&#039;, &#039;v&#039;, &#039;w&#039;, &#039;x&#039;, &#039;y&#039;, &#039;z&#039;,\n    &#039;0&#039;, &#039;1&#039;, &#039;2&#039;, &#039;3&#039;, &#039;4&#039;, &#039;5&#039;, &#039;6&#039;, &#039;7&#039;, &#039;8&#039;, &#039;9&#039;,\n    &#039;+&#039;, &#039;\/&#039;\n  };\n\n  public void write(byte&#x5B;] b) throws IOException\n  {\n  }\n  \n  private int m_col = 0;\n  private int m_i = 0;\n  private int&#x5B;] m_inbuf = new int&#x5B;3];\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">When I ran this using the URL https:\/\/java.com\/, it returned the following:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>URL : https:\/\/java.com\/\nUsername (optional) : \nPassword (optional) : \n&gt;&gt;&gt;&gt;\nConnecting to: https:\/\/java.com\/\nConnected...\n----------Method--------------\n&#91;0] HTTP\/1.1 200 OK\n----------Response Headers----\n&#91;1] Content-Type: text\/html; charset=UTF-8\n&#91;2] X-Frame-Options: SAMEORIGIN\n&#91;3] X-Oracle-Dms-Ecid: f6283c1a-349a-4181-b5c0-ae39da8c2640-00052eba\n&#91;4] X-Oracle-Dms-Rid: 0\n&#91;5] X-Akamai-Transformed: 9 1882 0 pmb=mRUM,2\n&#91;6] Cache-Control: max-age=60\n&#91;7] Expires: Tue, 09 Feb 2021 01:08:20 GMT\n&#91;8] Date: Tue, 09 Feb 2021 01:07:20 GMT\n&#91;9] Content-Length: 7475\n&#91;10] Connection: keep-alive\n&#91;11] Set-Cookie: AKA_A2=A; expires=Tue, 09-Feb-2021 02:07:20 GMT; path=\/; domain=com; secure; HttpOnly\n&#91;12] Server-Timing: cdn-cache; desc=HIT\n&#91;13] Server-Timing: edge; dur=32\n&#91;14] Link: &lt;https:\/\/static.oracle.com&gt;;rel=\"preconnect\",&lt;https:\/\/c.oracleinfinity.io&gt;;rel=\"preconnect\",&lt;https:\/\/dc.oracleinfinity.io&gt;;rel=\"preconnect\"\n&#91;15] Set-Cookie: akaalb_OCE_Failover=1612832900~op=JCOM_OCE:oceProdappJcomProdOrigin|~rv=56~m=oceProdappJcomProdOrigin:0|~os=2708f36cb43ca861e42dc0215e4669c5~id=34ac58c3548790706cbce606a4a7351a; path=\/; Expires=Tue, 09 Feb 2021 01:08:20 GMT; Secure; SameSite=None\n&#91;16] X-XSS-Protection: 1\nThere were 14 header lines\n----------Convenience functions----\ngetContentType: text\/html; charset=UTF-8\ngetContentLength: 7475\ngetContentEncoding: null\ngetDate: 1612832840000\ngetExpiration: 1612832900000\ngetLastModified: 0\n----------Content--------\n&#91;1] &lt;!DOCTYPE html&gt;\n&#91;2] &lt;html&gt;\n&#91;3] &lt;head&gt;\n&#91;4] &lt;script type=\"text\/javascript\"&gt;\n&#91;5] var SCSCacheKeys = {\n&#91;6] \tproduct: '_cache_1e73',\n&#91;7] \tsite: '_cache_1057',\n&#91;8] \ttheme: '_cache_c351',\n&#91;9] \tcomponent: '_cache_5a42',\n&#91;10] \tcaas: '_cache_5cff'\n. . .<\/code><\/pre>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Posting_Form_Data\"><\/span>Posting Form Data<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">The textbook also shows an example of how you can use&nbsp;<strong>URLConnection<\/strong>&nbsp;to <strong>POST<\/strong> data to a URL.&nbsp; In this particular example, the program connects to the&nbsp;<a rel=\"noreferrer noopener\" href=\"http:\/\/www.census.gov\/\" target=\"_blank\">US Census Bureau web site<\/a>&nbsp;to obtain population information about particular countries.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can go to&nbsp;<a href=\"http:\/\/www.census.gov\/ipc\/www\/idbsum.html\">http:\/\/www.census.gov\/ipc\/www\/idbsum.html<\/a>&nbsp;to obtain IDB Summary Demographic Data in more detail.&nbsp; However, this program just returns a simple output which it can display easily.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; auto-links: false; title: ; quick-code: false; notranslate\" title=\"\">\npackage networking;\n\nimport java.awt.BorderLayout;\nimport java.awt.event.ActionEvent;\nimport java.awt.event.ActionListener;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.net.HttpURLConnection;\nimport java.net.URL;\nimport java.net.URLConnection;\nimport java.net.URLEncoder;\nimport java.util.HashMap;\nimport java.util.Map;\nimport java.util.Scanner;\nimport javax.swing.JButton;\nimport javax.swing.JComboBox;\nimport javax.swing.JFrame;\nimport javax.swing.JPanel;\nimport javax.swing.JScrollPane;\nimport javax.swing.JTextArea;\n\n\/**\n * This program demonstrates how to use the URLConnection class for a POST request.\n *\/\npublic class PostTest\n{\n  public static void main(String&#x5B;] args)\n  {\n    JFrame frame = new PostTestFrame();\n    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);\n    frame.setVisible(true);\n  }\n}\n\nclass PostTestFrame extends JFrame\n{\n  \/**\n   * Makes a POST request and returns the server response.\n   * @param urlString the URL to post to\n   * @param nameValuePairs a map of name\/value pairs to supply in the request.\n   * @return the server reply (either from the input stream or the error stream)\n   *\/\n  public static String doPost(String urlString, Map&lt;String, String&gt; nameValuePairs)\n                           throws IOException\n  {\n    System.out.println(&quot;Connecting to URL: &quot; + urlString);\n\n    URL url = new URL(urlString);\n    URLConnection connection = url.openConnection();\n    connection.setDoOutput(true);\n    \n    PrintWriter out = new PrintWriter(connection.getOutputStream());\n    \n    boolean first = true;\n    \n    System.out.print(&quot;Query String : &quot;);\n    for (Map.Entry&lt;String, String&gt; pair : nameValuePairs.entrySet())\n    {\n      if (first)\n      {\n        first = false;\n      }\n      else \n      {\n        System.out.print(&#039;&amp;&#039;);\n        out.print(&#039;&amp;&#039;); \/\/ Output &#039;&amp;&#039; separator\n      }\n      String name = pair.getKey();\n      String value = pair.getValue();\n      out.print(name);\n      out.print(&#039;=&#039;);\n      value = URLEncoder.encode(value, &quot;UTF-8&quot;);\n      out.print(value);\n      System.out.print(name + &#039;=&#039; + value);\n    }\n    System.out.println();\n    \n    out.close();\n    \n    Scanner in;\n    StringBuilder response = new StringBuilder();\n    try\n    {\n      in = new Scanner(connection.getInputStream());\n    }\n    catch (IOException e)\n    {\n      if (!(connection instanceof HttpURLConnection)) \n        throw e;\n      InputStream err\n          = ((HttpURLConnection)connection).getErrorStream();\n      if (err == null) \n        throw e;\n      in = new Scanner(err);\n    }\n    while (in.hasNextLine())\n    {\n      response.append(in.nextLine());\n      response.append(&quot;\\n&quot;);\n    }\n    \n    in.close();\n    return response.toString();\n  }\n  \n  \/**\n   * Constructor\n   *\/\n  public PostTestFrame()\n  {\n    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);\n    setTitle(&quot;PostTest&quot;);\n    \n    JPanel northPanel = new JPanel();\n    add(northPanel, BorderLayout.NORTH);\n    \n    final JComboBox combo = new JComboBox();\n    for (int i = 0; i &lt; m_countries.length; i += 2)\n      combo.addItem(m_countries&#x5B;i]);\n    northPanel.add(combo);\n    \n    final JTextArea result = new JTextArea();\n    add(new JScrollPane(result));\n    \n    JButton getButton = new JButton(&quot;Get&quot;);\n    northPanel.add(getButton);\n    getButton.addActionListener(new ActionListener()\n      {\n        public void actionPerformed(ActionEvent event)\n        {\n          new Thread(new Runnable()\n          {\n            public void run()\n            {\n              final String SERVER_URL = &quot;http:\/\/www.census.gov\/cgi-bin\/ipc\/idbsprd&quot;;\n              result.setText(&quot;&quot;);\n              Map&lt;String, String&gt; post = new HashMap&lt;String, String&gt;();\n              post.put(&quot;tbl&quot;, &quot;001&quot;);\n              post.put(&quot;cty&quot;, m_countries&#x5B;2 * combo.getSelectedIndex() + 1]);\n              post.put(&quot;optyr&quot;, &quot;latest checked&quot;);\n              try\n              {\n                \/\/ Do the POST to the server URL\n                result.setText(doPost(SERVER_URL, post));\n              }\n              catch (IOException e)\n              {\n                result.setText(&quot;&quot; + e);\n              }\n            }\n          }).start();\n        }\n      }\n    );\n  }\n  \n  private static String&#x5B;] m_countries = \n  {\n    &quot;Afghanistan&quot;, &quot;AF&quot;, &quot;Albania&quot;, &quot;AL&quot;, &quot;Algeria&quot;, &quot;AG&quot;, &quot;American Samoa&quot;, &quot;AQ&quot;,\n    &quot;Andorra&quot;, &quot;AN&quot;, &quot;Angola&quot;, &quot;AO&quot;, &quot;Anguilla&quot;, &quot;AV&quot;, &quot;Antigua and Barbuda&quot;, &quot;AC&quot;,\n    &quot;Argentina&quot;, &quot;AR&quot;, &quot;Armenia&quot;, &quot;AM&quot;, &quot;Aruba&quot;, &quot;AA&quot;, &quot;Australia&quot;, &quot;AS&quot;, &quot;Austria&quot;, &quot;AU&quot;,\n    &quot;Azerbaijan&quot;, &quot;AJ&quot;, &quot;Bahamas, The&quot;, &quot;BF&quot;, &quot;Bahrain&quot;, &quot;BA&quot;, &quot;Bangladesh&quot;, &quot;BG&quot;,\n    &quot;Barbados&quot;, &quot;BB&quot;, &quot;Belarus&quot;, &quot;BO&quot;, &quot;Belgium&quot;, &quot;BE&quot;, &quot;Belize&quot;, &quot;BH&quot;, &quot;Benin&quot;, &quot;BN&quot;,\n    &quot;Bermuda&quot;, &quot;BD&quot;, &quot;Bhutan&quot;, &quot;BT&quot;, &quot;Bolivia&quot;, &quot;BL&quot;, &quot;Bosnia and Herzegovina&quot;, &quot;BK&quot;,\n    &quot;Botswana&quot;, &quot;BC&quot;, &quot;Brazil&quot;, &quot;BR&quot;, &quot;Brunei&quot;, &quot;BX&quot;, &quot;Bulgaria&quot;, &quot;BU&quot;, &quot;Burkina Faso&quot;, &quot;UV&quot;,\n    &quot;Burma&quot;, &quot;BM&quot;, &quot;Burundi&quot;, &quot;BY&quot;, &quot;Cambodia&quot;, &quot;CB&quot;, &quot;Cameroon&quot;, &quot;CM&quot;, &quot;Canada&quot;, &quot;CA&quot;,\n    &quot;Cape Verde&quot;, &quot;CV&quot;, &quot;Cayman Islands&quot;, &quot;CJ&quot;, &quot;Central African Republic&quot;, &quot;CT&quot;, &quot;Chad&quot;, &quot;CD&quot;,\n    &quot;Chile&quot;, &quot;CI&quot;, &quot;China&quot;, &quot;CH&quot;, &quot;Colombia&quot;, &quot;CO&quot;, &quot;Comoros&quot;, &quot;CN&quot;, &quot;Congo (Brazzaville&quot;, &quot;CF&quot;,\n    &quot;Congo (Kinshasa)&quot;, &quot;CG&quot;, &quot;Cook Islands&quot;, &quot;CW&quot;, &quot;Costa Rica&quot;, &quot;CS&quot;, &quot;Cote d&#039;Ivoire&quot;, &quot;IV&quot;,\n    &quot;Croatia&quot;, &quot;HR&quot;, &quot;Cuba&quot;, &quot;CU&quot;, &quot;Cyprus&quot;, &quot;CY&quot;, &quot;Czech Republic&quot;, &quot;EZ&quot;, &quot;Denmark&quot;, &quot;DA&quot;,\n    &quot;Djibouti&quot;, &quot;DJ&quot;, &quot;Dominica&quot;, &quot;DO&quot;, &quot;Dominican Republic&quot;, &quot;DR&quot;, &quot;East Timor&quot;, &quot;TT&quot;,\n    &quot;Ecuador&quot;, &quot;EC&quot;, &quot;Egypt&quot;, &quot;EG&quot;, &quot;El Salvador&quot;, &quot;ES&quot;, &quot;Equatorial Guinea&quot;, &quot;EK&quot;,\n    &quot;Eritrea&quot;, &quot;ER&quot;, &quot;Estonia&quot;, &quot;EN&quot;, &quot;Ethiopia&quot;, &quot;ET&quot;, &quot;Faroe Islands&quot;, &quot;FO&quot;, &quot;Fiji&quot;, &quot;FJ&quot;,\n    &quot;Finland&quot;, &quot;FI&quot;, &quot;France&quot;, &quot;FR&quot;, &quot;French Guiana&quot;, &quot;FG&quot;, &quot;French Polynesia&quot;, &quot;FP&quot;,\n    &quot;Gabon&quot;, &quot;GB&quot;, &quot;Gambia, The&quot;, &quot;GA&quot;, &quot;Gaza Strip&quot;, &quot;GZ&quot;, &quot;Georgia&quot;, &quot;GG&quot;, &quot;Germany&quot;, &quot;GM&quot;,\n    &quot;Ghana&quot;, &quot;GH&quot;, &quot;Gibraltar&quot;, &quot;GI&quot;, &quot;Greece&quot;, &quot;GR&quot;, &quot;Greenland&quot;, &quot;GL&quot;, &quot;Grenada&quot;, &quot;GJ&quot;,\n    &quot;Guadeloupe&quot;, &quot;GP&quot;, &quot;Guam&quot;, &quot;GQ&quot;, &quot;Guatemala&quot;, &quot;GT&quot;, &quot;Guernsey&quot;, &quot;GK&quot;, &quot;Guinea&quot;, &quot;GV&quot;,\n    &quot;Guinea-Bissau&quot;, &quot;PU&quot;, &quot;Guyana&quot;, &quot;GY&quot;, &quot;Haiti&quot;, &quot;HA&quot;, &quot;Honduras&quot;, &quot;HO&quot;,\n    &quot;Hong Kong S.A.R&quot;, &quot;HK&quot;, &quot;Hungary&quot;, &quot;HU&quot;, &quot;Iceland&quot;, &quot;IC&quot;, &quot;India&quot;, &quot;IN&quot;, &quot;Indonesia&quot;, &quot;ID&quot;,\n    &quot;Iran&quot;, &quot;IR&quot;, &quot;Iraq&quot;, &quot;IZ&quot;, &quot;Ireland&quot;, &quot;EI&quot;, &quot;Israel&quot;, &quot;IS&quot;, &quot;Italy&quot;, &quot;IT&quot;, &quot;Jamaica&quot;, &quot;JM&quot;,\n    &quot;Japan&quot;, &quot;JA&quot;, &quot;Jersey&quot;, &quot;JE&quot;, &quot;Jordan&quot;, &quot;JO&quot;, &quot;Kazakhstan&quot;, &quot;KZ&quot;, &quot;Kenya&quot;, &quot;KE&quot;,\n    &quot;Kiribati&quot;, &quot;KR&quot;, &quot;Korea, North&quot;, &quot;KN&quot;, &quot;Korea, South&quot;, &quot;KS&quot;, &quot;Kuwait&quot;, &quot;KU&quot;,\n    &quot;Kyrgyzstan&quot;, &quot;KG&quot;, &quot;Laos&quot;, &quot;LA&quot;, &quot;Latvia&quot;, &quot;LG&quot;, &quot;Lebanon&quot;, &quot;LE&quot;, &quot;Lesotho&quot;, &quot;LT&quot;,\n    &quot;Liberia&quot;, &quot;LI&quot;, &quot;Libya&quot;, &quot;LY&quot;, &quot;Liechtenstein&quot;, &quot;LS&quot;, &quot;Lithuania&quot;, &quot;LH&quot;, &quot;Luxembourg&quot;, &quot;LU&quot;,\n    &quot;Macau S.A.R&quot;, &quot;MC&quot;, &quot;Macedonia, The Former Yugo. Rep. of&quot;, &quot;MK&quot;, &quot;Madagascar&quot;, &quot;MA&quot;,\n    &quot;Malawi&quot;, &quot;MI&quot;, &quot;Malaysia&quot;, &quot;MY&quot;, &quot;Maldives&quot;, &quot;MV&quot;, &quot;Mali&quot;, &quot;ML&quot;, &quot;Malta&quot;, &quot;MT&quot;,\n    &quot;Man, Isle of&quot;, &quot;IM&quot;, &quot;Marshall Islands&quot;, &quot;RM&quot;, &quot;Martinique&quot;, &quot;MB&quot;, &quot;Mauritania&quot;, &quot;MR&quot;,\n    &quot;Mauritius&quot;, &quot;MP&quot;, &quot;Mayotte&quot;, &quot;MF&quot;, &quot;Mexico&quot;, &quot;MX&quot;, &quot;Micronesia, Federated States of&quot;, &quot;FM&quot;,\n    &quot;Moldova&quot;, &quot;MD&quot;, &quot;Monaco&quot;, &quot;MN&quot;, &quot;Mongolia&quot;, &quot;MG&quot;, &quot;Montserrat&quot;, &quot;MH&quot;, &quot;Morocco&quot;, &quot;MO&quot;,\n    &quot;Mozambique&quot;, &quot;MZ&quot;, &quot;Namibia&quot;, &quot;WA&quot;, &quot;Nauru&quot;, &quot;NR&quot;, &quot;Nepal&quot;, &quot;NP&quot;, &quot;Netherlands&quot;, &quot;NL&quot;,\n    &quot;Netherlands Antilles&quot;, &quot;NT&quot;, &quot;New Caledonia&quot;, &quot;NC&quot;, &quot;New Zealand&quot;, &quot;NZ&quot;, &quot;Nicaragua&quot;, &quot;NU&quot;,\n    &quot;Niger&quot;, &quot;NG&quot;, &quot;Nigeria&quot;, &quot;NI&quot;, &quot;Northern Mariana Islands&quot;, &quot;CQ&quot;, &quot;Norway&quot;, &quot;NO&quot;,\n    &quot;Oman&quot;, &quot;MU&quot;, &quot;Pakistan&quot;, &quot;PK&quot;, &quot;Palau&quot;, &quot;PS&quot;, &quot;Panama&quot;, &quot;PM&quot;, &quot;Papua New Guinea&quot;, &quot;PP&quot;,\n    &quot;Paraguay&quot;, &quot;PA&quot;, &quot;Peru&quot;, &quot;PE&quot;, &quot;Philippines&quot;, &quot;RP&quot;, &quot;Poland&quot;, &quot;PL&quot;, &quot;Portugal&quot;, &quot;PO&quot;,\n    &quot;Puerto Rico&quot;, &quot;RQ&quot;, &quot;Qatar&quot;, &quot;QA&quot;, &quot;Reunion&quot;, &quot;RE&quot;, &quot;Romania&quot;, &quot;RO&quot;, &quot;Russia&quot;, &quot;RS&quot;,\n    &quot;Rwanda&quot;, &quot;RW&quot;, &quot;Saint Helena&quot;, &quot;SH&quot;, &quot;Saint Kitts and Nevis&quot;, &quot;SC&quot;, &quot;Saint Lucia&quot;, &quot;ST&quot;,\n    &quot;Saint Pierre and Miquelon&quot;, &quot;SB&quot;, &quot;Saint Vincent and the Grenadines&quot;, &quot;VC&quot;, &quot;Samoa&quot;, &quot;WS&quot;,\n    &quot;San Marino&quot;, &quot;SM&quot;, &quot;Sao Tome and Principe&quot;, &quot;TP&quot;, &quot;Saudi Arabia&quot;, &quot;SA&quot;, &quot;Senegal&quot;, &quot;SG&quot;,\n    &quot;Serbia and Montenegro&quot;, &quot;YI&quot;, &quot;Seychelles&quot;, &quot;SE&quot;, &quot;Sierra Leone&quot;, &quot;SL&quot;, &quot;Singapore&quot;, &quot;SN&quot;,\n    &quot;Slovakia&quot;, &quot;LO&quot;, &quot;Slovenia&quot;, &quot;SI&quot;, &quot;Solomon Islands&quot;, &quot;BP&quot;, &quot;Somalia&quot;, &quot;SO&quot;,\n    &quot;South Africa&quot;, &quot;SF&quot;, &quot;Spain&quot;, &quot;SP&quot;, &quot;Sri Lanka&quot;, &quot;CE&quot;, &quot;Sudan&quot;, &quot;SU&quot;, &quot;Suriname&quot;, &quot;NS&quot;,\n    &quot;Swaziland&quot;, &quot;WZ&quot;, &quot;Sweden&quot;, &quot;SW&quot;, &quot;Switzerland&quot;, &quot;SZ&quot;, &quot;Syria&quot;, &quot;SY&quot;, &quot;Taiwan&quot;, &quot;TW&quot;,\n    &quot;Tajikistan&quot;, &quot;TI&quot;, &quot;Tanzania&quot;, &quot;TZ&quot;, &quot;Thailand&quot;, &quot;TH&quot;, &quot;Togo&quot;, &quot;TO&quot;, &quot;Tonga&quot;, &quot;TN&quot;,\n    &quot;Trinidad and Tobago&quot;, &quot;TD&quot;, &quot;Tunisia&quot;, &quot;TS&quot;, &quot;Turkey&quot;, &quot;TU&quot;, &quot;Turkmenistan&quot;, &quot;TX&quot;,\n    &quot;Turks and Caicos Islands&quot;, &quot;TK&quot;, &quot;Tuvalu&quot;, &quot;TV&quot;, &quot;Uganda&quot;, &quot;UG&quot;, &quot;Ukraine&quot;, &quot;UP&quot;,\n    &quot;United Arab Emirates&quot;, &quot;TC&quot;, &quot;United Kingdom&quot;, &quot;UK&quot;, &quot;United States&quot;, &quot;US&quot;, &quot;Uruguay&quot;, &quot;UY&quot;,\n    &quot;Uzbekistan&quot;, &quot;UZ&quot;, &quot;Vanuatu&quot;, &quot;NH&quot;, &quot;Venezuela&quot;, &quot;VE&quot;, &quot;Vietnam&quot;, &quot;VM&quot;,\n    &quot;Virgin Islands&quot;, &quot;VQ&quot;, &quot;Virgin Islands, British&quot;, &quot;VI&quot;, &quot;Wallis and Futuna&quot;, &quot;WF&quot;,\n    &quot;West Bank&quot;, &quot;WE&quot;, &quot;Western Sahara&quot;, &quot;WI&quot;, &quot;Yemen&quot;, &quot;YM&quot;, &quot;Zambia&quot;, &quot;ZA&quot;, &quot;Zimbabwe&quot;, &quot;ZI&quot;\n  };\n  \n  public static final int DEFAULT_WIDTH = 400;\n  public static final int DEFAULT_HEIGHT = 300;\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">When I ran this program originally, it displayed the following (I had already chosen the country (United Kingdom) and clicked on the <strong>Get<\/strong> button.)<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"alignleft size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"400\" height=\"300\" src=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-content\/uploads\/2021\/02\/Postin1.jpg\" alt=\"\" class=\"wp-image-490\" srcset=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-content\/uploads\/2021\/02\/Postin1.jpg 400w, https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-content\/uploads\/2021\/02\/Postin1-300x225.jpg 300w\" sizes=\"auto, (max-width: 400px) 100vw, 400px\" \/><\/figure><\/div>\n\n\n\n<div style=\"height:24px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>Unfortunately, it seems that this website has gone away, and I was unable to find a replacement for it. Thus, when I run this program now, it gives me:<\/p><\/blockquote>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"alignleft size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"814\" height=\"614\" src=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-content\/uploads\/2021\/02\/Screen-Shot-2021-02-10-at-12.56.30-PM.png\" alt=\"\" class=\"wp-image-491\" srcset=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-content\/uploads\/2021\/02\/Screen-Shot-2021-02-10-at-12.56.30-PM.png 814w, https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-content\/uploads\/2021\/02\/Screen-Shot-2021-02-10-at-12.56.30-PM-300x226.png 300w, https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-content\/uploads\/2021\/02\/Screen-Shot-2021-02-10-at-12.56.30-PM-768x579.png 768w\" sizes=\"auto, (max-width: 814px) 100vw, 814px\" \/><\/figure><\/div>\n\n\n\n<div style=\"height:18px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">and shows no content. It also outputs the following to System.out:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Connecting to URL: http:\/\/www.census.gov\/cgi-bin\/ipc\/idbsprd\nQuery String : cty=UK&amp;optyr=latest+checked&amp;tbl=001<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Alternative_Post_Example\"><\/span>Alternative Post Example<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">A later edition of the textbook has a different version of this <strong>PostTest<\/strong> program, which the author used to access the USPS website to look up the ZIP code for an address. It is rather more complex, showing more features of the <strong>HttpURLConnection<\/strong> class:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; auto-links: false; title: ; quick-code: false; notranslate\" title=\"\">\npackage post;\n\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.net.CookieHandler;\nimport java.net.CookieManager;\nimport java.net.CookiePolicy;\nimport java.net.HttpURLConnection;\nimport java.net.URL;\nimport java.net.URLEncoder;\nimport java.nio.charset.StandardCharsets;\nimport java.nio.file.Files;\nimport java.nio.file.Paths;\nimport java.util.Map;\nimport java.util.Properties;\nimport java.util.Scanner;\n\n\/**\n * This program demonstrates how to use the URLConnection class for a POST request.\n * \n *\/\npublic class PostTest\n{\n   \/**\n    * Main entry point\n    * @usage java properties-file\n    * @param args\n    * @throws IOException \n    *\/\n   public static void main(String&#x5B;] args) throws IOException\n   {\n      \/\/ Properties file default is post.properties\n      String propsFilename = args.length &gt; 0 ? args&#x5B;0] : &quot;post.properties&quot;; \n      Properties props = new Properties();\n      try (InputStream in = Files.newInputStream(Paths.get(propsFilename)))\n      {\n         props.load(in);\n      }\n      String urlString = props.remove(&quot;url&quot;).toString();\n      Object userAgent = props.remove(&quot;User-Agent&quot;);\n      Object redirects = props.remove(&quot;redirects&quot;);\n      CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ALL));\n      String result = doPost(new URL(urlString), props, \n         userAgent == null ? null : userAgent.toString(), \n         redirects == null ? -1 : Integer.parseInt(redirects.toString()));\n      System.out.println(result);\n   }   \n\n   \/**\n    * Do an HTTP POST.\n    * @param url the URL to post to\n    * @param nameValuePairs the query parameters\n    * @param userAgent the user agent to use, or null for the default user agent\n    * @param redirects the number of redirects to follow manually, or -1 for automatic\n    * redirects\n    * @return the data returned from the server\n    *\/\n   public static String doPost(URL url, Map&lt;Object, Object&gt; nameValuePairs, \n                               String userAgent, int redirects) throws IOException\n   {  \n      System.out.println(&quot;Connecting to URL: &quot; + url.toExternalForm());\n      \n      HttpURLConnection connection = (HttpURLConnection) url.openConnection();\n      if (userAgent != null)\n      {\n         System.out.println(&quot;User-Agent : &quot; + userAgent);\n         connection.setRequestProperty(&quot;User-Agent&quot;, userAgent);\n      }\n      \n      System.out.println(&quot;Redirects: &quot; + redirects);\n      \n      if (redirects &gt;= 0)\n         connection.setInstanceFollowRedirects(false);\n      \n      connection.setDoOutput(true);\n      \n      try (var out = new PrintWriter(connection.getOutputStream()))\n      {\n         var first = true;\n         System.out.print(&quot;Query String: &quot;);\n         for (Map.Entry&lt;Object, Object&gt; pair : nameValuePairs.entrySet())\n         {\n            if (first) \n                first = false;\n            else\n            {\n                out.print(&#039;&amp;&#039;);\n                System.out.print(&#039;&amp;&#039;);\n            }\n            String name = pair.getKey().toString();\n            String value = pair.getValue().toString();\n            out.print(name);\n            out.print(&#039;=&#039;);\n            value = URLEncoder.encode(value, StandardCharsets.UTF_8);\n            out.print(value);\n            System.out.print(name + &#039;=&#039; + value);\n         }\n         System.out.println();\n      }      \n      String encoding = connection.getContentEncoding();\n      if (encoding == null) \n          encoding = &quot;UTF-8&quot;;\n            \n      if (redirects &gt; 0)\n      {\n         int responseCode = connection.getResponseCode();\n         if (responseCode == HttpURLConnection.HTTP_MOVED_PERM \n               || responseCode == HttpURLConnection.HTTP_MOVED_TEMP\n               || responseCode == HttpURLConnection.HTTP_SEE_OTHER) \n         {\n            String location = connection.getHeaderField(&quot;Location&quot;);\n            if (location != null)\n            {\n               URL base = connection.getURL();\n               connection.disconnect();\n               return doPost(new URL(base, location), nameValuePairs, userAgent, \n                     redirects - 1);\n            }\n         }\n      }\n      else if (redirects == 0)\n      {\n         throw new IOException(&quot;Too many redirects&quot;);\n      }\n         \n      var response = new StringBuilder();\n      try (var in = new Scanner(connection.getInputStream(), encoding))\n      {\n         while (in.hasNextLine())\n         {\n            response.append(in.nextLine());\n            response.append(&quot;\\n&quot;);\n         }         \n      }\n      catch (IOException e)\n      {\n         InputStream err = connection.getErrorStream();\n         if (err == null) \n             throw e;\n         try (var in = new Scanner(err))\n         {\n            response.append(in.nextLine());\n            response.append(&quot;\\n&quot;);\n         }\n      }\n\n      return response.toString();\n   }\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">I supplied a <strong>Properties<\/strong> file for input to this program:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>User-Agent=Mozilla\/5.0 (Macintosh; Intel Mac OS X 11_2_0) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/88.0.4324.146 Safari\/537.36)\ntAddress=100 Amherst Street\nsState=NH\ntCity=Nashua\nurl=https\\:\/\/tools.usps.com\/go\/ZipLookupAction.action<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">When I ran the program, it output the following:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Connecting to URL: https:\/\/tools.usps.com\/go\/ZipLookupAction.action\nUser-Agent : Mozilla\/5.0 (Macintosh; Intel Mac OS X 11_2_0) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/88.0.4324.146 Safari\/537.36)\nRedirects: -1\nQuery String: tAddress=100+Amherst+Street&amp;sState=NH&amp;tCity=Nashua\n&lt;html lang=\"en\"&gt;\n&lt;head&gt;\n\t&lt;meta charset=\"utf-8\"&gt;\n\t&lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"&gt;\n\t&lt;meta name=\"\" content=\"\"&gt;\n\t&lt;title&gt;ZIP Code\u2122 Lookup | USPS&lt;\/title&gt;\n\t&lt;link rel=\"stylesheet\" href=\"\/styles\/libs\/bootstrap.min.css\"\/&gt;\n\t&lt;link rel=\"stylesheet\" href=\"\/styles\/default-styles.css\"\/&gt;\n\t&lt;link rel=\"stylesheet\" href=\"\/styles\/main-zip-code.css\"\/&gt;\n\t&lt;link rel=\"stylesheet\" href=\"\/styles\/footer-sb.css\"\/&gt;\n\t&lt;link rel=\"stylesheet\" href=\"\/styles\/main-sb.css\"\/&gt;\n\t&lt;link rel=\"stylesheet\" href=\"\/styles\/style.css\" \/&gt;\t\n\t&lt;style type=\"text\/css\"&gt;\n\t#shortcuts-menu-wrapper {\n\t\theight: auto !important;\n\t}\n\t&lt;\/style&gt;\n&lt;\/head&gt;\n&lt;body style=\"display:none;\"&gt;\n\n&#91;lots of content]. . .\n\t\n&lt;\/body&gt;\n&lt;\/html&gt;\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">It appears to ignore the query string parameters and simple provide the entire webpage.  Sigh&#8230;<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>They say that once you put something on the Web, it never goes away. Unfortunately, in this case, it appears not to be true.<\/p><\/blockquote>\n\n\n\n<div style=\"height:42px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Alternatives_for_Coding_for_the_Web\"><\/span>Alternatives for Coding for the Web<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>As you can see, programming for the Web\/HTTP is not for the faint of heart. It is complex! <\/p><p>Instead of doing it yourself, it makes more sense to use an existing, well-written and easily available substitute library such as Apache HttpClient (<strong><a href=\"http:\/\/hc.apache.org\/httpcomponents-client-ga\/\" target=\"_blank\" rel=\"noreferrer noopener\">http:\/\/hc.apache.org\/httpcomponents-client-ga\/<\/a><\/strong>)<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>If you&#8217;re interested in doing anything with the Internet, or anything with local area network (LAN), then you need to know something about networking.&nbsp; Java provides very good support for networking, and it&#8217;s quite easy to use.&nbsp; Indeed, that&#8217;s one significant reason why Java has become so popular and successful. Networking Basics Here is a [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":19,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_eb_attr":"","ocean_front_end_style_editor":"no","ocean_post_layout":"left-sidebar","ocean_both_sidebars_style":"","ocean_both_sidebars_content_width":0,"ocean_both_sidebars_sidebars_width":0,"ocean_sidebar":"ocs-course-topics-sidebar","ocean_second_sidebar":"0","ocean_disable_margins":"enable","ocean_add_body_class":"","ocean_shortcode_before_top_bar":"","ocean_shortcode_after_top_bar":"","ocean_shortcode_before_header":"","ocean_shortcode_after_header":"","ocean_has_shortcode":"","ocean_shortcode_after_title":"","ocean_shortcode_before_footer_widgets":"","ocean_shortcode_after_footer_widgets":"","ocean_shortcode_before_footer_bottom":"","ocean_shortcode_after_footer_bottom":"","ocean_display_top_bar":"default","ocean_display_header":"default","ocean_header_style":"","ocean_center_header_left_menu":"0","ocean_custom_header_template":"0","ocean_custom_logo":0,"ocean_custom_retina_logo":0,"ocean_custom_logo_max_width":0,"ocean_custom_logo_tablet_max_width":0,"ocean_custom_logo_mobile_max_width":0,"ocean_custom_logo_max_height":0,"ocean_custom_logo_tablet_max_height":0,"ocean_custom_logo_mobile_max_height":0,"ocean_header_custom_menu":"0","ocean_menu_typo_font_family":"0","ocean_menu_typo_font_subset":"","ocean_menu_typo_font_size":0,"ocean_menu_typo_font_size_tablet":0,"ocean_menu_typo_font_size_mobile":0,"ocean_menu_typo_font_size_unit":"px","ocean_menu_typo_font_weight":"","ocean_menu_typo_font_weight_tablet":"","ocean_menu_typo_font_weight_mobile":"","ocean_menu_typo_transform":"","ocean_menu_typo_transform_tablet":"","ocean_menu_typo_transform_mobile":"","ocean_menu_typo_line_height":0,"ocean_menu_typo_line_height_tablet":0,"ocean_menu_typo_line_height_mobile":0,"ocean_menu_typo_line_height_unit":"","ocean_menu_typo_spacing":0,"ocean_menu_typo_spacing_tablet":0,"ocean_menu_typo_spacing_mobile":0,"ocean_menu_typo_spacing_unit":"","ocean_menu_link_color":"","ocean_menu_link_color_hover":"","ocean_menu_link_color_active":"","ocean_menu_link_background":"","ocean_menu_link_hover_background":"","ocean_menu_link_active_background":"","ocean_menu_social_links_bg":"","ocean_menu_social_hover_links_bg":"","ocean_menu_social_links_color":"","ocean_menu_social_hover_links_color":"","ocean_disable_title":"default","ocean_disable_heading":"default","ocean_post_title":"","ocean_post_subheading":"","ocean_post_title_style":"","ocean_post_title_background_color":"","ocean_post_title_background":0,"ocean_post_title_bg_image_position":"","ocean_post_title_bg_image_attachment":"","ocean_post_title_bg_image_repeat":"","ocean_post_title_bg_image_size":"","ocean_post_title_height":0,"ocean_post_title_bg_overlay":0.5,"ocean_post_title_bg_overlay_color":"","ocean_disable_breadcrumbs":"default","ocean_breadcrumbs_color":"","ocean_breadcrumbs_separator_color":"","ocean_breadcrumbs_links_color":"","ocean_breadcrumbs_links_hover_color":"","ocean_display_footer_widgets":"default","ocean_display_footer_bottom":"default","ocean_custom_footer_template":"0","footnotes":""},"class_list":["post-429","page","type-page","status-publish","hentry","entry"],"_links":{"self":[{"href":"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-json\/wp\/v2\/pages\/429","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-json\/wp\/v2\/comments?post=429"}],"version-history":[{"count":29,"href":"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-json\/wp\/v2\/pages\/429\/revisions"}],"predecessor-version":[{"id":497,"href":"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-json\/wp\/v2\/pages\/429\/revisions\/497"}],"up":[{"embeddable":true,"href":"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-json\/wp\/v2\/pages\/19"}],"wp:attachment":[{"href":"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-json\/wp\/v2\/media?parent=429"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}