1

I have the following issue connecting to a AccessGard (newnet) solution that forwards TPC messages to my application from a POS.

Basically the AG automatically connects from an ip "X.X.X.2" to my pooled server but it never sends any data.

When the POS send the message for some reason the AG sends the TPC request from another IP "X.X.X.132" but it never triggers the serverSocket.accept()

With wiresharck I can see Keep Alive messages from the X.X.X.2 to my server every second. Also I can see the request incoming from ip "X.X.X.132" but it never reaches the server. All the incoming transmissions come to the same port.

here is my server :

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;
}

}

here the worker:

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;
}


}
  • I don't see how this is possible. If the 132 connection hasn't been created it has no business sending data, and your server host should be sending resets. You don't have any end of stream checking in your code. – user207421 Apr 21 '17 at 23:17
  • You are right , The sniffer was sending me "traffic" as far as I could see but it was the TCP handshake that was failing due to a network restriction in the firewall. It seems that the client side could send me messages but the server never reach the client back. – Oscar Gomez Marco Apr 23 '17 at 23:43

0 Answers0