Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

ServerSocket vs Socket

807606Mar 1 2007 — edited Mar 2 2007
Hi,

I'm not sure what the clear difference between a ServerSocket and a Socket is. Sure I know that you're supposed to use one for a server and one for a client, but what's the difference between them functionally?

Also, I'm creating a client-server program which, in terms of networking, should work just like a chat program. Now the only way I can think of having the clients of this program to be aware of any new chat messages sent by other clients is to have them constantly listening to the server. In that case, are they all servers? Should I be using the ServerSocket for all of them?

Finally, when I create a Socket, I supply it with a port number. Is this the port number of the client that's connecting, or the number of the server that it's trying to connect to? If it's the number of the server, then where do you define what port number the client uses?

Any help would be greatly appreciated...
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 30 2007
Added on Mar 1 2007
5 comments
1,007 views