代码如下: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希望有明白人给小弟解答,多谢各位高手了
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希望有明白人给小弟解答,多谢各位高手了
解决方案 »
- JAVA求助(续) Socket编程问题 请各位高手帮助!!!
- java网络通信问题
- 怎样让这个程序出来的界面正常点啊!原本是awt,但是改成swing就有问题了
- 构造两个线程,通过管道将一个进程读入的文件从另外一个进程中输出到另外一个文件。
- 通过JdbcOdbcDriver操作informax、Sql Server、Oracle有什么区别吗?
- 请帮我看看这个简单的问题!!!
- How to deploy ear file with command line utility?
- 关于如何制作软件操作手册的问题?
- 请问那里能下载JAVA?
- 在BEAN中怎么删除磁盘文件?
- 真急啊
- 请教一个java语法问题
修改为:
public static void main(String[] args) {
谢了
不能调用doService就把他搞成static就行了