Problems with connecting two sockets on the same application.
I have two applications running on the same computer. They are to converse with each other via TCP/IP sockets.
Application 1 is a second party application and I have no control over how it handles IO. It has two connections 1 is a write port and the other a listen port and when it is connecting to applications on the same computer then the ports cannot be the same.
Application 2 is my Java application that is to receive data from and pass data to Application 1. It accepts the connection of Application 1 by using a ServerSocket.accept() method. However there is a problem when I attempt to create a Socket that connects to the listen port of Application 1. When I attempt to create the second socket the socket that is created from the ServerSocket.accept() closes or stops the InputStream.
I need to have way for Application 2 to listen to the port that Application 1 writes to and write to the port that Application 1 listens to and they must be able to handle this at the same time.
Does anyone know what I could be doing wrong? Here's an example of what I'm seeing:
ServerSocket receiver = null;
Socket socket1 = null;
Socket socket2 = null;
receiver = new ServerSocket(6001);
socket1 = receiver.accept();
// here I would start handling socket1.getInputStream();
socket2 = new Socket("18.104.22.168", 6002);
// the line above breaks the InputStream from socket1