Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/378.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java SocketServer连接到AccessGuard 1000解决方案_Java_Tcp_Socketserver - Fatal编程技术网

Java SocketServer连接到AccessGuard 1000解决方案

Java SocketServer连接到AccessGuard 1000解决方案,java,tcp,socketserver,Java,Tcp,Socketserver,我在连接AccessGard(newnet)解决方案时遇到以下问题,该解决方案将TPC消息从POS转发到我的应用程序 基本上,AG会自动从ip“X.X.X.2”连接到我的池服务器,但它从不发送任何数据 当POS出于某种原因发送消息时,AG从另一个IP“X.X.X.132”发送TPC请求,但它从不触发serverSocket.accept() 通过wiresharck,我可以每秒看到从X.X.X.2到我的服务器的保持活动消息。我还可以看到来自ip“X.X.X.132”的请求,但它从未到达服务器。所

我在连接AccessGard(newnet)解决方案时遇到以下问题,该解决方案将TPC消息从POS转发到我的应用程序

基本上,AG会自动从ip“X.X.X.2”连接到我的池服务器,但它从不发送任何数据

当POS出于某种原因发送消息时,AG从另一个IP“X.X.X.132”发送TPC请求,但它从不触发serverSocket.accept()

通过wiresharck,我可以每秒看到从X.X.X.2到我的服务器的保持活动消息。我还可以看到来自ip“X.X.X.132”的请求,但它从未到达服务器。所有传入的传输都到同一端口

这是我的服务器:

public class Server2 {

protected int          serverPort   = 8005;
protected ServerSocket serverSocket = null;
protected boolean      isStopped    = false;
protected Thread       runningThread= null;
protected ExecutorService threadPool =  Executors.newFixedThreadPool(10);

public Server2()
{}

public void run(){
    openServerSocket();
    while(! isStopped()){
        Socket clientSocket = null;
        try {
            clientSocket = this.serverSocket.accept();
        } catch (IOException e) {
            if(isStopped()) {
                System.out.println("Server Stopped.") ;
                break;
            }
            throw new RuntimeException(
                "Error accepting client connection", e);
        }
        this.threadPool.execute(
            new WorkerRunnable(clientSocket,
                "Thread Pooled Server"));
    }
    this.threadPool.shutdown();
    System.out.println("Server Stopped.") ;
}

private void openServerSocket() {
    try {
        this.serverSocket = new ServerSocket(this.serverPort);
    } catch (IOException e) {
        throw new RuntimeException("Cannot open port 8005", e);
    }
}
private synchronized boolean isStopped() {
    return this.isStopped;
}

}
工人们:

public class WorkerRunnable implements Runnable
{

private static final Logger logger = Logger.getLogger(WorkerRunnable.class);
protected Socket connectionSocket = null;
protected String serverText   = null;

public WorkerRunnable(Socket connectionSocket, String serverText) {
    this.connectionSocket = connectionSocket;
    this.serverText   = serverText;
}

public void run() {
    try {
        System.out.println(read());


    } catch (IOException e) {
        //report exception somewhere.
        e.printStackTrace();
    }
}

private String read() throws IOException 
{
    InputStream in = connectionSocket.getInputStream();
    byte[] m = new byte[2];
    in.read(m,0,2);
    ByteBuffer wrapped = ByteBuffer.wrap(m); 
    short num = wrapped.getShort(); 
    logger.info("IN message length:" + num +" Hexa:" + String.format("%02x", m[0]) + String.format("%02x", m[1])); System.out.println("IN message length:" + num +" Hexa:" + String.format("%02x", m[0]) + String.format("%02x", m[1]));        
    byte[] message = new byte[num];
    in.read(message,0,num);
    String inMessage = Util.bytesToHex(message);
    logger.info("Full message:" + inMessage);  System.out.println("Full message:" + inMessage );
    return inMessage;
}


}

我不明白这怎么可能。如果尚未创建132连接,则无法发送数据,您的服务器主机应该正在发送重置。您的代码中没有任何流结束检查。您是对的,嗅探器向我发送了我所能看到的“流量”,但由于防火墙中的网络限制,TCP握手失败了。客户端似乎可以向我发送消息,但服务器永远无法返回客户端。我不明白这是怎么可能的。如果尚未创建132连接,则无法发送数据,您的服务器主机应该正在发送重置。您的代码中没有任何流结束检查。您是对的,嗅探器向我发送了我所能看到的“流量”,但由于防火墙中的网络限制,TCP握手失败了。似乎客户端可以向我发送消息,但服务器永远无法返回客户端。