package com; import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.PrintWriter; import java.net.Socket; public class ServerThread extends Thread{ private Socket socket ; public ServerThread(Socket socket){ this.socket = socket; } public void run(){ try{ InputStream is = socket.getInputStream(); OutputStream os = socket.getOutputStream(); BufferedReader br = new BufferedReader(new InputStreamReader(is)); PrintWriter pw =new PrintWriter(os); String temp = br.readLine();//读取客户端输入的消息 System.out.println("服务器端消息:" +temp);//服务器端简单处理一下。 sleep(3000); pw.println("接收到了"); pw.close(); br.close(); socket.close(); }catch(Exception rr){ rr.printStackTrace(); } } public static void main(String[] args) { new Server().start(); } }
最近下载更多