• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • Carey Brown
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • fred rosenberger
  • salvin francis

ServerSocket vs Socket

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 23901
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 23901
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh ok.Thank you Henry that makes things clear nd laso gives me idea about solving the problem.
 
Get off me! Here, read this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic