代码如下:server端
import java.net.*; import java.io.*;
public class EchoServer {
void doService(Socket clientSocket) {
try{
DataInputStream in = new DataInputStream(clientSocket.getInputStream());
PrintStream out = new PrintStream(clientSocket.getOutputStream());
while (true) {String theLine=in.readLine(); out.println(theLine); }
}catch (IOException e) { System.err.println(e); }}public void main(String[] args) {
ServerSocket listenSocket;
try {
listenSocket = new ServerSocket(8888); // port
while(true) {
Socket clientSocket = listenSocket.accept();
System.err.println("Connexion from:" + clientSocket.getInetAddress());
doService(clientSocket);
}}
catch (Exception e) { System.err.println(e); }
}}client端
import java.net.*; import java.io.*;
public class EchoClient {
public static void main(String[] args) {
Socket theSocket;
DataInputStream theInputStream; DataInputStream userInput;
PrintStream theOutputStream;
String theLine;
try {
theSocket = new Socket(InetAddress.getLocalHost(),8888);
theInputStream = new DataInputStream(theSocket.getInputStream());
theOutputStream = new PrintStream(theSocket.getOutputStream());
userInput = new DataInputStream(System.in);
while (true) {
theLine = userInput.readLine();
if (theLine.equals(".")) break;
theOutputStream.println(theLine);
System.out.println(theInputStream.readLine());
}
} catch (UnknownHostException e) { System.err.println(e);
} catch (IOException e) { System.err.println(e); } } }
不知道为什么编译的时候没有问题,但是在运行服务端的时候,显示如下错误?
Exception in thread "main" java.lang.NoSuchMethodError: main希望有明白人给小弟解答,多谢各位高手了