import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
import java.net.*;
public class Server_p315 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO 自动生成方法存根
ServerSocket server=null;
Server_thread thread;
Socket you=null;
while(true){
try{
server=new ServerSocket(4331);
}
catch(IOException IOE4){
System.out.print("Now Listening...");
}
try{
System.out.println("Waiting for Cilents's message");
you=server.accept();
System.out.print("The Cilents' address"+you.getInetAddress());
}
catch(IOException IOE5){
System.out.println("waiting for Cilent");
}
if(you!=null){
new Server_thread(you).start();
}
}
}
}
class Server_thread extends Thread{
Socket socket;
DataInputStream in=null;
DataOutputStream out=null;
String s=null;
boolean quesion=false;
Server_thread(Socket t){
socket=t;
try{
out=new DataOutputStream(socket.getOutputStream());
in=new DataInputStream(socket.getInputStream());
}
catch(IOException IOE6){}
}
public void run(){
while(true){
double a[]=new double[3];
int i=0;
try{
s=in.readUTF();
quesion=false;
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("Please enter some words");
quesion=true;
}
}
if(quesion==false){
double p=(a[0]+a[1]+a[2])/2.0;
out.writeUTF(""+Math.sqrt(p*a[0]*(p-a[1])*(p-a[2])));
}
}
catch(IOException IOE7){
System.out.print("LostCilent");
return;
}
}
}
}
java程序设计基础教程第二版: Server_p315
最新推荐文章于 2022-11-08 11:01:54 发布