Question

what is a socket? what is the difference between a socket object and a ServerSocket object?

what is a socket?

what is the difference between a socket object and a ServerSocket object?
0 0
Add a comment Improve this question Transcribed image text
Answer #1

What is a socket?

When we carry out TCP/IP communication,
All details that are necessary for the communication is provided by the Socket.
It's doesn't matter whether it is server side or client side.


For another port, another socket is created.
Server-side use code is given below for its own socket.


then, Server will use that socket for communication with client.
Given below code is client's socket.

Difference between socket and Serversocket?

The question here arises is if Socket is doing all our work
then what is the need of ServerSocket?

And the answer is because of
working pattern of communication on TCP/IP protocol.


When two programs talk on TCP/IP Communication,
normally one will passively listen or wait on a <IP: port> &
the another one will actively connect to it.

We can see that at starting phase of the communication,
the two sides will have very different behaviors.
So two different classes can be used to reflect differences.

1)socket class will encapsulates behavior of the active or client side.
2)While ServerSocket class will encapsulate behavior of the server or passsive side.


So When ServerSocket completes it's listening task and detects incoming connection,
it will accept() and creats new socket to communicate.

Same, in "java.ino" package,
We can find that ServerSocketChannel and Socketchannel classes
They will work like this..



Like, Please.

Comment if you have any Queries.

Add a comment
Know the answer?
Add Answer to:
what is a socket? what is the difference between a socket object and a ServerSocket object?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT