View Single Post
  #1 (permalink)  
Old 01-12-2009, 11:41 AM
JRSofty JRSofty is offline
Junior Member
 

Join Date: Nov 2009
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
JRSofty is on a distinguished road
Default 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:
Code:

ServerSocket receiver = null;
Socket socket1 = null;
Socket socket2 = null;

try
{
receiver = new ServerSocket(6001);
socket1 = receiver.accept();
// here I would start handling socket1.getInputStream();
socket2 = new Socket("172.10.10.21", 6002);
// the line above breaks the InputStream from socket1
}
catch(Exception e)
{

}
Reply With Quote Share this thread on Facebook
Sponsored Links
Java Training from DevelopIntelligence