ホスト
| 日本語 | 主催者 |
| 英語 | host |
| ふりがな | ほすと |
| フリガナ | ホスト |
ネットワーク上に存在するマシン。
ネットワークで他のマシンから接続されるマシンを「ホスト」という。
そのマシンに付けられた名前を「ホスト名」と言う。
ホスト名は、ローカルなネットワークでホストの数が少ない場合には単純な名前を指定し、インターネットのようにグローバルなネットワークではドメイン名を用いる。
また、IPアドレスもホスト名代わりとなる。
「ホスト」は「サーバー」と同意の場合もある。
「サーバー」は、マシンを指す場合と、そのマシン上で動作してソケット接続を受け付けるアプリケーションを指す場合とがあり、前者の場合、ホストと同意となる。
ネットワークで他のマシンから接続されるマシンを「ホスト」という。
そのマシンに付けられた名前を「ホスト名」と言う。
ホスト名は、ローカルなネットワークでホストの数が少ない場合には単純な名前を指定し、インターネットのようにグローバルなネットワークではドメイン名を用いる。
また、IPアドレスもホスト名代わりとなる。
「ホスト」は「サーバー」と同意の場合もある。
「サーバー」は、マシンを指す場合と、そのマシン上で動作してソケット接続を受け付けるアプリケーションを指す場合とがあり、前者の場合、ホストと同意となる。
参考サイト
- (参考サイトはありません)
// Sample.java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.HttpURLConnection;
public class Sample
{
public static void main( String[] args )
{
BufferedReader bufferedReader = null;
HttpURLConnection httpURLConnection = null;
try
{
// プロトコル。
String protocol = "http";
// ホストを示すドメイン名。
String host = "www.yahoo.co.jp";
// ポート番号。
int port = 80;
// ファイルパス。
String filePath = "/index.html";
// アクセスするためのURLクラスを作ります。
URL url = new URL( protocol, host, port, filePath );
System.out.println( url.toString() );
// http://www.yahoo.co.jp:80/index.html
// Content-Typeの文字コード(注:実際には、HEADで文字コードを取得してから指定します)。
String charSet = "EUC-JP";
// リクエストのメソッド。
String method = "GET";
// 指定されたURLを元にリクエストを発行します。
httpURLConnection = (HttpURLConnection)url.openConnection();
httpURLConnection.setRequestMethod( method );
// リクエストの結果を取得します。
InputStreamReader inputStreamReader = new InputStreamReader( httpURLConnection.getInputStream(), charSet );
bufferedReader = new BufferedReader( inputStreamReader );
// 全行出力します。
while( true )
{
String oneLine = bufferedReader.readLine();
if( oneLine == null )
{
break;
}
System.out.println( oneLine );
}
// <html>
// <head>
// <title>Yahoo! JAPAN</title>
// (以下略)
}
catch( IOException e )
{
e.printStackTrace();
}
finally
{
if( bufferedReader != null )
{
try
{
bufferedReader.close();
}
catch( IOException e )
{
e.printStackTrace();
}
}
if( httpURLConnection != null )
{
httpURLConnection.disconnect();
}
}
}
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.HttpURLConnection;
public class Sample
{
public static void main( String[] args )
{
BufferedReader bufferedReader = null;
HttpURLConnection httpURLConnection = null;
try
{
// プロトコル。
String protocol = "http";
// ホストを示すドメイン名。
String host = "www.yahoo.co.jp";
// ポート番号。
int port = 80;
// ファイルパス。
String filePath = "/index.html";
// アクセスするためのURLクラスを作ります。
URL url = new URL( protocol, host, port, filePath );
System.out.println( url.toString() );
// http://www.yahoo.co.jp:80/index.html
// Content-Typeの文字コード(注:実際には、HEADで文字コードを取得してから指定します)。
String charSet = "EUC-JP";
// リクエストのメソッド。
String method = "GET";
// 指定されたURLを元にリクエストを発行します。
httpURLConnection = (HttpURLConnection)url.openConnection();
httpURLConnection.setRequestMethod( method );
// リクエストの結果を取得します。
InputStreamReader inputStreamReader = new InputStreamReader( httpURLConnection.getInputStream(), charSet );
bufferedReader = new BufferedReader( inputStreamReader );
// 全行出力します。
while( true )
{
String oneLine = bufferedReader.readLine();
if( oneLine == null )
{
break;
}
System.out.println( oneLine );
}
// <html>
// <head>
// <title>Yahoo! JAPAN</title>
// (以下略)
}
catch( IOException e )
{
e.printStackTrace();
}
finally
{
if( bufferedReader != null )
{
try
{
bufferedReader.close();
}
catch( IOException e )
{
e.printStackTrace();
}
}
if( httpURLConnection != null )
{
httpURLConnection.disconnect();
}
}
}
}
// Sample.java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.HttpURLConnection;
public class Sample
{
public static void main( String[] args )
{
BufferedReader bufferedReader = null;
HttpURLConnection httpURLConnection = null;
try
{
// プロトコル。
String protocol = "http";
// ホストを示すドメイン名。
String host = "www.yahoo.co.jp";
// ポート番号。
int port = 80;
// ファイルパス。
String filePath = "/index.html";
// アクセスするためのURLクラスを作ります。
URL url = new URL( protocol, host, port, filePath );
System.out.println( url.toString() );
// http://www.yahoo.co.jp:80/index.html
// Content-Typeの文字コード(注:実際には、HEADで文字コードを取得してから指定します)。
String charSet = "EUC-JP";
// リクエストのメソッド。
String method = "GET";
// 指定されたURLを元にリクエストを発行します。
httpURLConnection = (HttpURLConnection)url.openConnection();
httpURLConnection.setRequestMethod( method );
// リクエストの結果を取得します。
InputStreamReader inputStreamReader = new InputStreamReader( httpURLConnection.getInputStream(), charSet );
bufferedReader = new BufferedReader( inputStreamReader );
// 全行出力します。
while( true )
{
String oneLine = bufferedReader.readLine();
if( oneLine == null )
{
break;
}
System.out.println( oneLine );
}
// <html>
// <head>
// <title>Yahoo! JAPAN</title>
// (以下略)
}
catch( IOException e )
{
e.printStackTrace();
}
finally
{
if( bufferedReader != null )
{
try
{
bufferedReader.close();
}
catch( IOException e )
{
e.printStackTrace();
}
}
if( httpURLConnection != null )
{
httpURLConnection.disconnect();
}
}
}
}




