这个程序在eclipse中为什么执行不了?

EchoServer.javaimportjava.io.*;importjava.net.*;classEchoServerThreadextendsThread{pr... EchoServer.java

import java.io.*;
import java.net.*;
class EchoServerThread extends Thread{
private Socket connection;
public EchoServerThread(Socket c){
connection=c;
start();
}
public void run(){
try{
DataInputStream in=new DataInputStream(connection.getInputStream());
DataOutputStream out=new DataOutputStream(connection.getOutputStream());
System.out.println("has opened I/O byte stream on the connection to client");
String line=new String("");
while(!line.equalsIgnoreCase("QUIT")){
line=in.readUTF();
System.out.println("Echoing:"+line);
if(line.toUpperCase().equals("SHUTDOWN")){
EchoServer.running=false;
line="QUIT";
}
out.writeUTF(line);
}
in.close();out.close();
connection.close();
System.out.println("Connection close.");
}
catch(IOException ioe){
System.out.println("Connection closed unexpectedly.");
}
}
}
public class EchoServer {
static boolean running=true;
public static void main(String[] args){
try{
ServerSocket server=new ServerSocket(Integer.parseInt(args[0]));
System.out.println("Server started on"+server.getLocalPort());
while(running){
Socket connection=server.accept();
System.out.println("New connection moved to thread.");
EchoServerThread handler=new EchoServerThread(connection);
}
server.close();
System.out.println("server has closed!");
}
catch(IOException ioe){
System.err.println("Error:"+ioe);
}
}
}

EchoClient.java

import java.net.*;
import java.io.*;
public class EchoClient {
public static void main(String[] args){
try{
Socket connection=new Socket(args[0],8000);
System.out.println("Connection established");
DataInputStream in=new DataInputStream(connection.getInputStream());
DataOutputStream out=new DataOutputStream(connection.getOutputStream());
System.out.println("has opened the I/O byte stream on the connection to server");
String line=new String("");
while(!line.toUpperCase().equals("QUIT")){
System.out.print("Enter string:");
line=readString();
System.out.println("Sending string to server……");
out.writeUTF(line);
System.out.println("Waiting for server response……");
line=in.readUTF();
System.out.println("Received:"+line);
}
in.close();out.close();
connection.close();
System.out.println("connection closed!");
}
catch(UnknownHostException uhe){
System.err.println("Unknown host:"+args[0]);
}
catch(IOException ioe){
System.err.println("IOException:"+ioe);
}
}
public static String readString(){
String str=new String();
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
try{
str=in.readLine();
}catch(IOException e){
System.out.println("Console.readString:Unknow error……");
System.exit(-1);
}
return str;
}
}
展开
 我来答
loshamo
2011-05-23
知道答主
回答量:23
采纳率:0%
帮助的人:17.3万
展开全部

你是怎么运行的啊?

EchoClient.java

import java.net.*;

import java.io.*;

public class EchoClient {

public static void main(String[] args){

try{

Socket connection=new Socket(args[0],8000);

。。。。。。。。。。。。。。。。。

Socket connection=new Socket(args[0],8000);

你的程序在运行的时候需要你传参数过来 给你发2个图片看看

追问
运行时有异常。
EchoClient.java
追答
你把代码改一下,
Socket connection=new Socket(args[0],8000);
ServerSocket server=new ServerSocket(Integer.parseInt(args[0]));

改成 Socket connection=new Socket("127.0.0.1",8000);
ServerSocket server=new ServerSocket(8000);
试试
luxssdh
2011-05-24 · TA获得超过401个赞
知道小有建树答主
回答量:670
采纳率:50%
帮助的人:485万
展开全部
Java类必须要有Main函数作为程序执行的入口,如下所示:
public void main(String...args){
//下面开始写你要执行的代码

}
之后即可运行。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式