aspose file tools*
The moose likes Servlets and the fly likes unallocated ports on the server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "unallocated ports on the server" Watch "unallocated ports on the server" New topic
Author

unallocated ports on the server

Sameera Abeysinghe
Ranch Hand

Joined: Nov 15, 2004
Posts: 104
Hi,
I have this program in a web site. So the solution to this problem has to be from jsp or servlets. Lot of clients will be sending video streams to the server from deferent ports and the server receives it.
So the program can not have static ports or the port numbers can not be hard coded.
So when a Clint calls the pp.jsp or pp.class (a servlet) it must send the port this Clint must use
This pp is just a name to say that the answer must be a jsp or servlet

I think u all got the situation
Now my problem is how I can get a list or unallocated ports on the server.
Unallocated is the numbers of ports not used at given time

Thank You
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

I'm not sure what you mean by "port".

Maybe you could explain, in some more detail, what it is you're trying to do.
And please, when doing so, use real words.
[ December 14, 2005: Message edited by: Ben Souther ]

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Sameera Abeysinghe
Ranch Hand

Joined: Nov 15, 2004
Posts: 104
I am coding a video conferencing software using JMF. I use AVTransmit to transmit the video from the client to the server. To transmit we need a port number. Since lot of clients will be using this I don�t think can give a static port. Because at a one time only one client can use one port another can not use the same port. So the port number has to be dynamic.
So I will have servlet or a jsp when a client calls this it will check the available ports on the server and tell the client what port to use

And my problem is how can I do this

check the available ports on the server

----------------------------------------------
Maybe you could explain, in some more detail, what it is you're trying to do.
And please, when doing so, use real words.

think your refereeing to my spelling mistakes
I am sorry
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18991
    
    8

Because at a one time only one client can use one port another can not use the same port.
Is this a restriction of the software you are using? Because in general that is not a true statement. You will notice for example that hundreds of clients can connect to your web server simultaneously, all using port 80.
Sameera Abeysinghe
Ranch Hand

Joined: Nov 15, 2004
Posts: 104
from : Paul Clapham
Qu : Is this a restriction of the software you are using?
An : No Way

Qu : Because in general that is not a true statement.
An : R U sure ?

Qu : You will notice for example that hundreds of clients can connect to your web server simultaneously, all using port 80.
An : yes but to send data and keep the connection alive they dont use port 80 it just to connect after that it transfers to another port. when ur connecting to a site open dos window and run netstat u will see lots of connections from the site u r connected all from defferent ports.

i dont know how much my (above) theorie is true and it is the same way java ports work (in java sockets and video transfering in JMF)

it is up to any one to correct me
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18991
    
    8

The fact remains that to connect to an HTTP server, the client always connects to port 80. The same is true of FTP servers, MySQL servers, CVS servers: the client always connects to a predefined port and the servers can handle more than one client at a time, even if the clients have long-running connections (e.g. 2-megabyte downloads). It isn't obvious to me why your server should be any different, even though I don't know anything about JMF.

However if you want to notify the client of what port to use (as FTP servers do, I believe), you don't need a list of unused ports. Almost all the ports will be unused, so just try ports sequentially starting from somewhere above 1024 until you find an unused port.
ramprasad madathil
Ranch Hand

Joined: Jan 24, 2005
Posts: 489


And please, when doing so, use real words.

think your refereeing to my spelling mistakes


No. Ben was referring to the use of sms lingo like below which you continue to use

R U sure ?
ur connecting.

Please use real words in future posts.

thanks,
ram.
Sameera Abeysinghe
Ranch Hand

Joined: Nov 15, 2004
Posts: 104
Thanks a lot
I am very sorry from now on I will do it
----------------------------------------------------------
You may be right. But let�s take java sockets.
If there�s 3 machines(PC�s), one is a server. PC A is connecting to server in port 5000. If PC B is also connecting to server by port 5000 it gives an error( hope this happens to every one) so PC B cant use port 5000. Because in PC B port 5000 may be free but it is not free on the server. It has to use port 5001 or some thing else. Now both port 5000 and 5001 are busy on the server. If another client wants to connect he has to use some other port.
If I keep going finding free ports one by one it takes time. So is there any other way to do this

Thank a lot
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18991
    
    8

If I keep going finding free ports one by one it takes time. So is there any other way to do this
Of course it takes time. Everything takes time. If we didn't do things that took time, we wouldn't have any programs. The question is, does it take too much time? I doubt it. You're trying to optimize something that you don't know needs optimizing.
ramprasad madathil
Ranch Hand

Joined: Jan 24, 2005
Posts: 489


If there�s 3 machines(PC�s), one is a server. PC A is connecting to server in port 5000. If PC B is also connecting to server by port 5000 it gives an error( hope this happens to every one) so PC B cant use port 5000.


If what you meant is that the server listens on port 5000 and since it has already accepted a connection from PCA, it cannot accept one from PCB, you are wrong - it can.
If you are speaking of plain server sockets (java.net.ServerSocket), then there is an accept() method, which accepts an incoming connection and returns (after handing over the client object to a thread - but then that's implementation specific) so that the server is free to accept other connections.

Specific to your problem, you can rest reassured that the web server which hosts your application will listen on one port only (which is configurable)
and it can receive multiple requests on that single post. For each request, it initiates a cycle of events (which is container specific) and which ensures that the request is processed. But the point to note is that the server does not wait for the request processing to complete for it to accept other requests. This may be too general, but would suffice to address your concerns, I believe.

cheers,
ram.
Sameera Abeysinghe
Ranch Hand

Joined: Nov 15, 2004
Posts: 104
Hi
Thank you for the answers.
Ok
Now my problem is,
Is it same with JMF?
I am using AVTransmit2.java found in JMF solution page to transfer video from client to server. At the same time a servlet is called with the transferring port. Using that port the sevrlet will start AVRecevice2.java found in JMF solution page.
Now if several clients send video don�t they have to use deferent ports?
Don�t I have to give deferent ports fro deferent users?
Or dose JMJF behave like ServeSockets?
Do JMF use the port I give only to connect and latter change to some other port (Like Java Sockets)?

Thank you,
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: unallocated ports on the server