Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / November 2005

Tip: Looking for answers? Try searching our database.

Java Socket Programming

Thread view: 
geek - 05 Nov 2005 17:25 GMT
Hi guys,

I am a newbie to Java programming.
I have a question regarding TCP/IP socket programming.
When a client connects to a server it needs to know the server address
and its port no (lets call this portA).
When a server listens to connection requests from clients, can a server
choose any port number above 1023 randomly? Or does it needs to know
that server is sending me the data on this port(portA) thus it should
listen on only that port?

So in essence does a client send request on a server's specified port
and the server listens on the same port?

Can anybody please clear this doubt.

Thanks for help in advance.

MJ
Gordon Beaton - 05 Nov 2005 16:48 GMT
> When a server listens to connection requests from clients, can a
> server choose any port number above 1023 randomly? Or does it needs
[quoted text clipped - 3 lines]
> So in essence does a client send request on a server's specified
> port and the server listens on the same port?

The server listens to a specific port. The connection is established
when a client connects to that port. So although it doesn't matter
what port the server chooses, it must be known to the client in
advance. For that reason, most common services are on "well known"
port numbers. For your own applications you can choose any free port
above 1023, and it's sufficient that your clients know which port
you've chosen.

/gordon

Signature

[  do not email me copies of your followups  ]
g o r d o n + n e w s @  b a l d e r 1 3 . s e

geek - 05 Nov 2005 19:20 GMT
Thanks Gordon for the help.
That solves all problems I have been having.
geek - 06 Nov 2005 19:00 GMT
So that also means that server doesn't need to know Client's address?
Then how does it sends reply to client?

Thanks for help.
Gordon Beaton - 06 Nov 2005 18:25 GMT
> So that also means that server doesn't need to know Client's
> address? Then how does it sends reply to client?

The server doesn't need to know the client address in order to reply.
The Socket that was created when the server accepted the client
connection contains the information necessary to reach the client. The
server just sends replies using that Socket.

/gordon

Signature

[  do not email me copies of your followups  ]
g o r d o n + n e w s @  b a l d e r 1 3 . s e

Roedy Green - 06 Nov 2005 23:21 GMT
>So that also means that server doesn't need to know Client's address?
>Then how does it sends reply to client?

please read http://mindprod.com/jgloss/tcpip.html

it explains that.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Roedy Green - 05 Nov 2005 17:57 GMT
>I have a question regarding TCP/IP socket programming.

You might like to read this background on TCP/IP. It should clear this
up and similar mysteries.

See http://mindprod.com/jgloss/tcpip.html

Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.