Java the difference of Socket and ServerSocket in using port -


at server side, use

socket server = serversocket.accept(); 

to create socket. after socket created, can create new thread handle input/output stream of socket. can go listening @ same port , create new socket if there further connection requests come in. since created serversocket @ specific port, of course not create serversocket @ port again.

so understanding, can conclude that, @ server side, can create multiple sockets under 1 port? (similar web server does)

actually question is, @ client side, when creating socket, can specify local port want use. after have successful created client socket @ local port, can reuse port other client socket? port bind socket permenantly until socket closed (or port close)? since there no "listening" concept @ client side, able same thing serversocket (refer serversocket can create multiple socket under 1 port)?

i confused how client side handle port , socket, because comparing serversocket client socket.

please point me correct direction, know thinking somehow wrong. much.

so understanding, can conclude that, @ server side, can create multiple sockets under 1 port? (similar web server does)

you're confusing terminology. serversocket.accept() accepts connection, , wraps endpoint in socket. endpoint has same local port number serversocket, definition per rfc 793, , therefore wrapping socket.

actually question is, @ client side, when creating socket, can specify local port want use.

we can, if ever so.

after have successful created client socket @ local port, can reuse port other client socket?

no.

does port bind socket permenantly until socket closed (or port close)?

yes, or rather other way round: socket bound port.

since there no "listening" concept @ client side, able same thing serversocket (refer serversocket can create multiple socket under 1 port)?

no.


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -