为什么80%的码农都做不了架构师?>>>
自定义服务端
/*
演示客户端与服务端
客户端:浏览器
服务端:自定义*/
import java.net.*;
import java.io.*;
class ServerDemo{public static void main(String[] args)throws Exception{ServerSocket ss=new ServerSocket(11000);Socket s=ss.accept();System.out.println(s.getInetAddress().getHostAddress());PrintWriter out=new PrintWriter(s.getOutputStream(),true);out.println("你好");s.close();ss.close();}
}
Tomcat服务端
/*
客户端:浏览器
服务端:Tomcat服务器*/这是我的主页
欢迎光临
自定义浏览器-tomcat服务端
import java.io.*;
import java.net.*;
class myIE{public static void main(String[] args)throws Exception{Socket s=new Socket("192.168.1.135",8080);PrintWriter out=new PrintWriter(s.getOutputStream(),true);out.println("GET /myweb/demo.html HTTP/1.1");out.println("Accept: */*");out.println("Accept-Language: zh-CN,zh");out.println("Host: 192.168.1.135:11000");out.println("Connection: keep-alive");out.println("");out.println("");out.println("");BufferedReader bufr=new BufferedReader(new InputStreamReader(s.getInputStream()));String line=null;while((line=bufr.readLine())!=null){System.out.println(line);}s.close();}
}// GET / HTTP/1.1 请求行
// Host: 192.168.1.135:11000
// Connection: keep-alive
// Upgrade-Insecure-Requests: 1
// User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko)
// Chrome/51.0.2704.106 Safari/537.36
// Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0
// .8
// Accept-Encoding: gzip, deflate, sdch
// Accept-Language: zh-CN,zh;q=0.8
URL-URLConnection
import java.net.*;
import java.io.*;
class URLConnectionDemo{public static void main(String[] args)throws Exception{URL url=new URL("http://192.168.1.135:8080/myweb/demo.html");URLConnection conn=url.openConnection();System.out.println(conn);InputStream in=conn.getInputStream();byte[]buf=new byte[1024];int len=in.read(buf);System.out.println(new String(buf,0,len));}
}
域名解析
想要将主机名翻译成IP地址,需要域名解析,DNS