943,752 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 728
  • Java RSS
May 23rd, 2009
0

Socket Programming Ports

Expand Post »
Hello friends,
As usual .. when i have a problem ... daniweb.com is here . So I need some information from you. Ok, let me explain ... I am currently developing a chat application ! Ok ... everything works fine till now but I have doubts.

My application uses 3 ports, one for the general chat room, one for personal chat and one for file transfer. I have used 3 random ports .. 4321, 4532 and 4533.

Is there a standard port to used?

What will happen if I run this application on a computer where these 3 ports is in used?

And finally, how to know if a port is in used or not ?

Thanks a lot for your answers guys.

Regards,
Mike.
Similar Threads
Reputation Points: 6
Solved Threads: 0
Junior Poster
neutralfox is offline Offline
124 posts
since Mar 2009
May 23rd, 2009
0

Re: Socket Programming Ports

http://www.iana.org/assignments/port-numbers
You definitely need to avoid anything with a published port number.

As for picking ports which are unused, it's a crap shoot.
I would suggest that you make the listening ports configurable.

If your s/w takes off and everyone wants to use it, then getting an assigned IANA port number would generally solve the problem.
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
May 23rd, 2009
0

Re: Socket Programming Ports

Hi,
  • There are 65536 ports (TCP) i.e 0-65535
  • Port No 0 to 1023 are reserved for well known services (http, ftp, telnet)
  • If you try to use a port already in use, you will get a BindException
  • You can run a port scanner program to check what your ports are doing
Reputation Points: 32
Solved Threads: 14
Junior Poster
tuse is offline Offline
173 posts
since Jul 2007
May 23rd, 2009
0

Re: Socket Programming Ports

Thanks for the answer guys! To Salem, you suggest me to allow the user to configure or set the port himself? OK, but will it make my program less user friendly ?

I understand you but how MSN works ?

To tuse, I got your point ... I must create a form to allow the user to choose another port if there is a BindException. Thanks...

But still I want to know MSN Messenger works !!! I made some research but can't find anything useful that can help me to make my program more efficient.

Thanks a lot for your answers.
Regards,
Mike
Last edited by neutralfox; May 23rd, 2009 at 10:21 am.
Reputation Points: 6
Solved Threads: 0
Junior Poster
neutralfox is offline Offline
124 posts
since Mar 2009
May 23rd, 2009
0

Re: Socket Programming Ports

Click to Expand / Collapse  Quote originally posted by neutralfox ...

To tuse, I got your point ... I must create a form to allow the user to choose another port if there is a BindException.

Yeah, using the try-catch
Reputation Points: 32
Solved Threads: 14
Junior Poster
tuse is offline Offline
173 posts
since Jul 2007
May 23rd, 2009
0

Re: Socket Programming Ports

Thanks tuse.

@ Salem, in the link you send me:

Mention that:

"CCP Registered ports SHOULD NOT be used without IANA registration.
The registration procedure is defined in [RFC4340], Section 19.9."

So I can't use port 0 - 49151.
What happened if i used one of these ports ? Will I have to pay a fine? And how much is the registration ?

Because its just a open source software which I am developing for learning and to share among friends.

Thanks a lot for your answers.
Reputation Points: 6
Solved Threads: 0
Junior Poster
neutralfox is offline Offline
124 posts
since Mar 2009
May 23rd, 2009
0

Re: Socket Programming Ports

If you use a port in the non-restricted range you would be unlucky to hit one that was in use. Maybe all you need to do if you do get a BindException is to just try the next one (etc) until its OK.
Featured Poster
Reputation Points: 1910
Solved Threads: 951
Posting Expert
JamesCherrill is offline Offline
5,768 posts
since Apr 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC