socket server 启动问题

tomcat起不来,
web.xml配置为:

socket
servlet.SocketServlet
1

SocketServlet类:
public class SocketServlet extends HttpServlet{
public void init(ServletConfig cfg) throws ServletException {

super.init(cfg);

new SocketServer();

}

}
socket server 服务器端代码如下:

public class SocketServer {
// 该服务器的端口号
final int RECEIVE_PORT = 4447;
// ReceiveServer的构造器
public SocketServer() {
ServerSocket serverSocket = null; //ServerSocket的实例
Socket request = null; //用户请求的套接字
Thread receiveThread = null; //需启动的线程
try {
// 初始化ServerSocket
serverSocket = new ServerSocket(RECEIVE_PORT);
while (true) { // 等待用户请
request = serverSocket.accept();
// 接收客户机连接请求
receiveThread = new ServerThread(request);
// 生成serverThread的实例
receiveThread.start();
// 启动serverThread线程
}
} catch (IOException e) {
System.out.println(e.getMessage());
System.exit(0);
}
}
}
class ServerThread extends Thread {
// 用户连接的通信套接字
Socket clientRequest;

// serverThread的构造器
public ServerThread(Socket s) {
this.clientRequest = s;
}
// 线程的执行方法
public void run() {
try {
DataInputStream input = new DataInputStream(clientRequest.getInputStream());
DataOutputStream output = new DataOutputStream(clientRequest.getOutputStream());
//客户端请求传过来的String(这里是可以的,能收到客户端请求的String)
String paraInfoXML = input.readUTF();
/*返回结果*/
String result = "" ;

SAXReader reader=new SAXReader();
StringReader sr=new StringReader(paraInfoXML);
org.xml.sax.InputSource is=new org.xml.sax.InputSource(sr);
try {
Document doc=reader.read(is);
/*业务逻辑*/

        } catch (DocumentException e) {
            e.printStackTrace();
        }
        output.writeUTF(result);
        output.flush();
        output.close();
        input.close();
        clientRequest.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

}

2个回答

查看log先

tomcat-home/log/data.log

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!