java运行显示在类中找不到主方法 请将主方法定义为......
packageexer15_3;importjava.io.BufferedInputStream;importjava.io.BufferedOutputStream;...
package exer15_3;import java.io.BufferedInputStream;import java.io.BufferedOutputStream;import java.io.DataInputStream;import java.io.DataOutputStream;import java.io.IOException;import java.net.ServerSocket;import java.net.Socket;public class Server { private ServerSocket server; private Socket client; private DataInputStream in; private DataOutputStream out; private Boolean clientWantSay = false; public Server() throws IOException { server = new ServerSocket(8080); } public void startListen() throws IOException { client = server.accept(); in = new DataInputStream(new BufferedInputStream(client.getInputStream())); out = new DataOutputStream(new BufferedOutputStream(client.getOutputStream())); } public void send(String message) throws IOException { out.writeUTF(message); out.flush(); } public String accept() throws IOException { return in.readUTF(); } public void close() { try { if(in != null) { in.close(); } if(out != null) { out.close(); } server.close(); client.close(); } catch (Exception ex) {} } public void acceptRequest() throws IOException { int acc = in.readInt(); if(acc == 1) { clientWantSay = true; } else { clientWantSay= false; } } public Boolean getClientWantSay() { return clientWantSay; } public void answerToSay() throws IOException { out.writeInt(1); out.flush(); } public void answerNotSay() throws IOException { out.writeInt(0); out.flush(); } public String communicate(String sendStr) throws IOException { String accStr = null; //从客户端接收的话 if (this.getClientWantSay()) { //客户端有话想说 accStr = this.accept(); } else { //客户端无话可说 if (sendStr == null) { //服务器无话可说 this.answerNotSay(); } else { //服务器有话想说 this.answerToSay(); this.send(sendStr); } } return accStr; }}
展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询