Go Back   Java Programming Forums > Java Standard Edition Programming Help > Java Networking


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-12-2009, 11:41 AM
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
  #2 (permalink)  
Old 02-12-2009, 08:01 AM
Json's Avatar
Super Moderator
 

Join Date: Jul 2009
Location: Manchester, United Kingdom
Posts: 1,157
Thanks: 54
Thanked 136 Times in 132 Posts
Json will become famous soon enoughJson will become famous soon enoughJson will become famous soon enough

I'm feeling Happy
Default Re: Problems with connecting two sockets on the same application.

Why use two different ports for reading and writing?

Why not just open one socket and read/write on it?

// Json
Reply With Quote
Reply

Tags
inputstream, serversocket, socket

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



Similar Threads
Thread Thread Starter Forum Replies Last Post
for chat application, is it necessary sockets and mutithreading in servlets? chinni Java Servlet 1 20-10-2009 11:31 AM
java application connecting to a server wildheart25c Java Networking 2 17-09-2009 12:22 PM
Help about connecting DB to java! java_cs JDBC & Databases 1 11-09-2009 05:39 PM
connecting two classes? chronoz13 Object Oriented Programming 9 01-09-2009 08:15 PM
Connecting to Oracle from within Eclipse kairamr Java IDEs 1 12-11-2008 09:16 PM


100 most searched terms
Search Cloud
2 dimensional arraylist java 2d arraylist java actionlistener actionlistener in java addactionlistener addactionlistener java convert double to integer java double format java double to integer in java double to integer java drag en drop programmeren java eclipse shortcut keys exception in thread "awt-eventqueue-0" java.lang.outofmemoryerror: java heap space exception in thread "main" java.lang.nullpointerexception exception in thread "main" java.lang.outofmemoryerror: java heap space format double in java format double java get mouse position java java 2d arraylist java actionlistener java double format java double formatting java double to int java double to integer java format double java forum java forums java get mouse position java list to map java mouse position java programming forum java programming forums java send keystrokes to another application java two dimensional arraylist java.io.ioexception: premature eof java.lang.classformaterror: truncated class file java.lang.outofmemoryerror: java heap space java.util.arraylist jbutton action jbutton actionlistener jbutton java jtextarea font jtextfield font size jxl.read.biff.biffexception: unable to recognize ole stream programming mutators and generics smack api two dimensional arraylist two dimensional arraylist java unable to sendviapost to url what is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?

All times are GMT. The time now is 01:50 AM.
Powered by vBulletin® Copyright ©2000-2009, Jelsoft Enterprises Ltd.