TCP编程——网络编程详细源码

时间:2013-07-29 04:51:02
【文件属性】:

文件名称:TCP编程——网络编程详细源码

文件大小:3.72MB

文件格式:ZIP

更新时间:2013-07-29 04:51:02

SOCKET编程

熟练掌握TCP方式的SOCKET编程 public void run() { try { // 构造输入流缓存 BufferedReader bufReader = new BufferedReader( new InputStreamReader(clientInput)); // 按行读取输入内容 String strLine = bufReader.readLine(); if ("OVER".equalsIgnoreCase(strLine)) { // 结束输入流 PrintWriter printWriter = new PrintWriter(clientOutput, true); printWriter.println("OVER"); } else { // 输入正方形边长,并输入其边长及面积 double side = Double.parseDouble(strLine); side = Double.parseDouble(strLine); System.out.println("Side of Square Received: " + side); double squareArea = side * side; String str = "Side: " + side + " Square:" + squareArea; PrintWriter printWriter = new PrintWriter(clientOutput, true); printWriter.println(str); System.out.println("Finish sending to client!"); } clientInput.close(); clientOutput.close(); clientSocket.close(); } catch (IOException e) { e.printStackTrace(); } }


网友评论