プログラムのネットワークプロトコルについて質問します
下のように URLConnections クラスと sockets クラスでは使用してるプロトコルが違うのか
googleからの反応が異なります
URLConnections クラスは反応を示さず
sockets クラスは読み込めます
そこで、図のように、URLConnectionsクラスとsocketsクラスが使用している
TCP/IP階層図では URLConnectionsクラスとsocketsクラスはどの階層に該当するのでしょうか?
import java.io.*; import java.net.*; import java.util.Date; //================================================================================ class URLConnections { public URLConnections() { try{ int character; URL url = new URL( "http://www.google.co.jp" ); URLConnection urlconnection = url.openConnection(); int contentlength = urlconnection.getContentLength(); if( contentlength > 0 ) { InputStream in = urlconnection.getInputStream(); while( (character = in.read() ) != -1 ) { System.out.print( (char)character ); } } }catch(Exception e) { System.out.println( "URLConnections で例外発生"); } } } //================================================================================ class sockets { public sockets() { try { System.out.println( "socket start" ); Socket s = new Socket( "www.google.co.jp", 80 ); BufferedReader in = new BufferedReader( new InputStreamReader( s.getInputStream() ) ); PrintWriter out = new PrintWriter( s.getOutputStream() ); out.print( "GET /index.html\n\n" ); out.flush(); String line; while( (line=in.readLine())!= null ){ System.out.println( line ); } System.out.println( "socket end" ); }catch(Exception e) { System.out.println( "例外発生" ); } } } //================================================================================ public class app { public static void main( String[/url] args) { URLConnections u = new URLConnections(); System.out.println( "end1\n" ); sockets s = new sockets(); System.out.println( "end2\n" ); } }
相互リンクさせてもらいます
http://oshiete.goo.ne.jp/qa/6105408.htmlt=