ServerDemo

package com.tz.util.screen;

import java.io.InputStream;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * 演示客服端和服务端
 * 1.客服端,浏览器
 * 服务端,自定义
 * 2.客服端:浏览器
 * 服务端:tomcat服务器
 * 3.客服端:自定义
 * 服务端:tomcat服务器
 *
 */
//1
public 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());
  
  InputStream in=s.getInputStream();
  byte[] buf=new byte[1024];
  int len=in.read(buf);
  System.out.println(new String(buf,0,len));
  
  PrintWriter out=new PrintWriter(s.getOutputStream(),true);
  out.println("<font color='red' size='7'>连接客服端</font>");
  
  s.close();
  ss.close();
 }

}

MyIE

package com.tz.util.screen;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;


public class MyIE {
 public static void main(String[] args) throws Exception, Exception {
  Socket s=new Socket("192.168.1.254",8080);
  PrintWriter out=new PrintWriter(s.getOutputStream(),true);
  out.println("Accept:*/*");
  
  BufferedReader bufr=new BufferedReader(new InputStreamReader(s.getInputStream()));
  String line=null;
  while ((line=bufr.readLine())!=null) {
   System.out.println(line);
  }
  s.close();
  
 }

}

你可能感兴趣的:(ServerDemo)