?? computer_server.java
字號:
import java.io.*;import java.net.*;import java.util.*;import java.sql.*;public class Computer_server { public static void main(String args[]) { ServerSocket server=null;Server_thread thread; Socket you=null; while(true) { try{ server=new ServerSocket(4331);} catch(IOException e1) {System.out.println("正在監聽");} try{ you=server.accept();} catch (IOException e) {System.out.println("正在等待客戶");} if(you!=null) {new Server_thread(you).start(); } else {continue;} } }}class Server_thread extends Thread{ Socket socket;Connection Con=null;Statement Stmt=null; DataOutputStream out=null;DataInputStream in=null;int n=0; String s=null; Server_thread(Socket t) { socket=t; try {in=new DataInputStream(socket.getInputStream()); out=new DataOutputStream(socket.getOutputStream()); } catch (IOException e) {} } public void run() { while(true) { double a[]=new double[3] ;int i=0; try{s=in.readUTF(); StringTokenizer fenxi=new StringTokenizer(s," ,"); while(fenxi.hasMoreTokens()) { String temp=fenxi.nextToken(); try{a[i]=Double.valueOf(temp).doubleValue();i++;} catch(NumberFormatException e){out.writeUTF("請輸入數字字符"); } } double p=(a[0]+a[1]+a[2])/2.0; out.writeUTF(" "+Math.sqrt(p*(p-a[0])*(p-a[1])*(p-a[2]))); sleep(2); } catch(InterruptedException e){} catch (IOException e) {System.out.println("客戶離開");Thread.currentThread().yield();break; } } } }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -