• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ServerSocket vs Socket

 
Gaurav Wadhwani
Ranch Hand
Posts: 68
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am unable to understand the difference. ServerSocket is used to create a server that can accept and send responses to a client. And client which is made by Socket, requests the server. But the client can also respond since it has both input and output streams.
In a case, where i want to make 10 such units - which can receive and send responses to each other -> i can make them all clients or all servers, isnt? That way server and client behave the same.
 
Henry Wong
author
Marshal
Pie
Posts: 20836
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gaurav Wadhwani wrote:I am unable to understand the difference. ServerSocket is used to create a server that can accept and send responses to a client. And client which is made by Socket, requests the server. But the client can also respond since it has both input and output streams.
In a case, where i want to make 10 such units - which can receive and send responses to each other -> i can make them all clients or all servers, isnt? That way server and client behave the same.



It's what happens *before* the plumbing is setup. The server socket sits on a port to accept connection from clients. The client sockets makes the connection requests to the server.

If all you have are servers, then you have everybody waiting for connections -- with no connections actually being made. If all you have are clients, then you have everybody trying to connect -- with nobody actually accepting the connections.

Henry
 
Gaurav Wadhwani
Ranch Hand
Posts: 68
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

If all you have are servers, then you have everybody waiting for connections -- with no connections actually being made. If all you have are clients, then you have everybody trying to connect -- with nobody actually accepting the connections.


So, does it mean that servers cant request and clients cant accept?

If that is so, then how do i model my problem where there are 10 units which must communicate with each other. If i have to make a server and client for each unit that would be not efficient.
 
Henry Wong
author
Marshal
Pie
Posts: 20836
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gaurav Wadhwani wrote:
So, does it mean that servers cant request and clients cant accept?


Well, that is how TCP works. Server sockets accept, and client socket initiate the connections. If you want something else, Java also supports UDP, over either unicast or multicast.


Gaurav Wadhwani wrote:
If that is so, then how do i model my problem where there are 10 units which must communicate with each other. If i have to make a server and client for each unit that would be not efficient.


These are server sockets and client sockets -- not full blown server / client as defined in the application sense. Don't know what you mean by "not efficient" -- as that would imply that there is another way to do TCP.

Henry
 
Gaurav Wadhwani
Ranch Hand
Posts: 68
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh ok.Thank you Henry that makes things clear nd laso gives me idea about solving the problem.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic