Building a client application: (Port number where a JAVA client-program runs + Build a listener to get data from web service).

I'm trying to connect to a web service data source.
The way the service works is like this:
1.) First, I need to call a LOGIN method. The LOGIN method has two arguments: the IP and the port number where the data source infrastructure will connect to and send the data.
2.) Second, there's a method to request the type of data that I need.
3.) Then lastly after I request type of data that I need, the infrastructure will connect to the port I specify and start sending data.

So the questions are:
1.) In the first step, how can I know the port number that the JAVA program uses to go outside?
So that I can supply this information to the LOGIN method along with the IP address (that I can get easily using InetAddress).

2.) How do I build the listener to receive stream of data that is being pushed from the server?

I'm using J2SE 1.5.

Thanks in advance for all the help.
Who is Participating?
1. If you can choose your client side port for the server app to connect to, choose a port >1024, perhaps something memorable like 22222

2. This depends on the protocol the server is using. If it's using JMS, then you'll need to use JMS on the port you chose in 1.
Are you sure this is a web service? Web services usually use the HTTP port
rnicholusAuthor Commented:
Yes, this is a web service that I need to access from a data provider.
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

If it's running on a non-standard port

a. You'll need to know what that port is - you can't guess
b. You'll probably need to use custom Socket programming to consume it, unless of course it's just a normal webservice running on a non-standard port
rnicholusAuthor Commented:
>> a. You'll need to know what that port is - you can't guess
Is there anyway I know from the JAVA program itself which port it's running on so that
my JAVA program can send that information (the IP and the port number) to the LOGIN method() of the web service?
Then the web-service data source will be able to push the data to exactly where my JAVA program is currently running.
>>Is there anyway I know from the JAVA program itself

If you have control of the port, you can choose it. Otherwise do a

netstat -ban

to try to determine which port it's listening on
rnicholusAuthor Commented:
In your last post, could you please point out where is the info. for me to choose which port the reader is running on?
>>where is the info. for me to choose which port the reader is running on?

If you have access to it, wherever its Socket is created
rnicholusAuthor Commented:

Thanks for the ongoing help. I think I'm still confused about the overall concept here.
Below I include some snippets of my code that hopefully will help the discussion.

In the login() method below, I need to provide the IP and PORT number .
The way it works is that after I request subscription data the data-provider infrastructure will connect to the IP and PORT I
specify and start sending data.  

What I'm not sure is:
1.) Which port number I should provide in the code? Can I just choose any port?
What needs to be considered when I choose the port?

2.) After successful login() call and subscribe() call below? How should I build listener to listen to the data?
I read somewhere that I need to use JAVA Messaging Service?

MyWebServiceLocator locator = new MyWebServiceLocator();
MyWebServiceServerSoap speedService = locator.getMyWebServiceServerSoap

// ******************************
// *** LOGIN ***
// ******************************
login_result = speedService.login(IP, PORT);"LOGIN status: " + login_result);

// ******************************
// *** SUBSCRIBE ***
// ******************************
if ( login_result == true )
subscribe_result = speedService.subscribe("type1Data", true);"SUBSCRIBE status: " + subscribe_result);

Thanks again for the ongoing help.
rnicholusAuthor Commented:
Hi CEHJ, sorry for replying so late.

I have several more questions:

1.) How do I know the protocol the server is using?
2.) Can I build a listener using native JAVA API?

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.