BAD packet signature 18245 错误解决

问题描述


Aug 28, 2017 8:04:40 AM org.apache.jk.common.MsgAjp processHeader

SEVERE: BAD packet signature 18245
Aug 28, 2017 8:04:40 AM org.apache.jk.common.ChannelSocket processConnection
SEVERE: Error, processing connection
java.lang.IndexOutOfBoundsException
        at java.io.BufferedInputStream.read(BufferedInputStream.java:327)
        at org.apache.jk.common.ChannelSocket.read(ChannelSocket.java:628)
        at org.apache.jk.common.ChannelSocket.receive(ChannelSocket.java:585)
        at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:693)
        at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:898)
        at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:690)

        at java.lang.Thread.run(Thread.java:748)


原因,WEB请求访问端口不正确。也就是说在浏览器中输入的URL端口号是AJP协议的端口号,而不是WEB服务的端口号。

下面的例子中ARJ协议端口号为8999,真正的WEB服务端口号应为8989,所以,若使用8999访问,会出现上面的错误信息。

 <Connector port="8999" protocol="AJP/1.3" redirectPort="8443" />

解决:将访问的URL端口号修改为WEB服务的端口号即8989而不是8999。

参考:

http://blog.csdn.net/hongweigg/article/details/37811005


import java.io.DataInputStream; import java.io.EOFException; import java.io.IOException; import java.net.ServerSocket; import java.net.Socket; public class Server { ServerSocket ss; Socket s ; Clients clients; DataInputStream dis; boolean startServer = false; public void startServer(){ try { ss = new ServerSocket(8888);//8888是TCP端口号 startServer = true; while(startServer){ s = ss.accept(); System.out.println(" connected!"); clients = new Clients(s); new Thread(clients).start(); } }catch(IOException e){ e.printStackTrace(); }finally{ try { ss.close(); } catch (IOException e) { e.printStackTrace(); } } } public static void main(String[] args) { new Server().startServer(); } } class Clients implements Runnable{//包装类,把外部连接的client包装 private Socket s; private boolean isConnected = false ; private DataInputStream dis; public Clients(Socket s) { this.s = s; try { isConnected = true; dis = new DataInputStream(s.getInputStream()); } catch (IOException e) { e.printStackTrace(); } } @Override public void run() { while(isConnected){ try { String str = dis.readUTF();//阻塞:它会一直等待 System.out.println(str); } catch (EOFException e){ System.out.println("Client is closed!"); }catch (IOException e1) { e1.printStackTrace(); }finally{ try { if(dis!=null) { dis.close(); }else{ ; } if(s!=null) { s.close(); }else{ ; } } catch (IOException e) { e.printStackTrace(); } } } } } import java.io.DataOutputStream; import java.io.IOException; import java.io.PrintWriter; import java.net.Socket; import java.net.UnknownHostException; import java.util.Scanner; public class Client { Socket s; PrintWriter pw; DataOutputStream dos; String line = ""; Scanner reader = new Scanner(System.in); public void startClient(){ try { s = new Socket("127.0.0.1", 8888); dos = new DataOutputStream(s.getOutputStream()); System.out.println("connected"); do{ System.out.print("please input:"); line = reader.next(); dos.writeUTF(line); dos.flush(); }while(!line.equals("bye")); dos.close(); s.close(); } catch (UnknownHostException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } public static void main(String[] args) { new Client().startClient(); } } java.net.SocketException: socket closed at java.net.SocketInputStream.socketRead0(Native Method) at java.net.SocketInputStream.read(Unknown Source) at java.net.SocketInputStream.read(Unknown Source) at java.net.SocketInputStream.read(Unknown Source) at java.io.DataInputStream.readUnsignedShort(Unknown Source) at java.io.DataInputStream.readUTF(Unknown Source) at java.io.DataInputStream.readUTF(Unknown Source) at Clients.run(Server.java:75) at java.lang.Thread.run(Unknown Source)
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页