• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

In a chat program is ServerSocket implemented in both end ?

 
Ranch Hand
Posts: 50
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am very new to java socket programming. I am going to write a multi user chat program. Now, do I have to implement ServerSocket in both end for listening for connection request from the other end ? What I understand is that ServerSocket is listening from a socket. If there is a request and accept that then it open a general socket to communicate to the other end. So the question is that both client implement ServerSocket.

Thank you.
 
author
Posts: 23958
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

The answer is... it depends. Are you proposing that both clients implement a server socket, and nothing else? Or are you proposing that they also use a socket to connect to each other's server socket, or if there is a third party that connects to the server sockets?

Henry
 
Muztaba Hasanat
Ranch Hand
Posts: 50
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Henry Wong wrote:
The answer is... it depends. Are you proposing that both clients implement a server socket, and nothing else? Or are you proposing that they also use a socket to connect to each other's server socket, or if there is a third party that connects to the server sockets?

Henry



Thanks for the reply. This will be a very simple chat program. To listen from a certain socket I do I have to implement ServerSocket? Or the general socket can listen from a socket? The problem is I am not understand what is the point to make a server in a chat program. Like if there a client in two pc then this two client could make contact with each other. Do I have to implement ServerSocket to listen in both client side ? Or I have to implement a Server and then that two clients communicate via this server?

 
Henry Wong
author
Posts: 23958
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

Muztaba Hasanat wrote:
To listen from a certain socket I do I have to implement ServerSocket? Or the general socket can listen from a socket? The problem is I am not understand what is the point to make a server in a chat program.



Do you understand the difference between the rendezvous socket and the data sockets? Once a data connection is established, with a connection of a socket from one end, and the socket returned from the server socket on the other end, communication is full duplex. Both sides can write to the data sockets, and both sides can read.

The ServerSocket class implements the rendezvous socket. It is *not* for data. It is to establish the data sockets... so, no ServerSocket, means no data sockets, means no communications.

Henry
 
Sheriff
Posts: 28371
99
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's possible that you have decided that the purpose of a chat application is to allow two people to chat. And I suspect you haven't noticed another requirement, namely that the two people need to be able to find each other first. How do you plan to do that?
 
Muztaba Hasanat
Ranch Hand
Posts: 50
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Henry Wong wrote:

Muztaba Hasanat wrote:
To listen from a certain socket I do I have to implement ServerSocket? Or the general socket can listen from a socket? The problem is I am not understand what is the point to make a server in a chat program.



Do you understand the difference between the rendezvous socket and the data sockets? Once a data connection is established, with a connection of a socket from one end, and the socket returned from the server socket on the other end, communication is full duplex. Both sides can write to the data sockets, and both sides can read.

The ServerSocket class implements the rendezvous socket. It is *not* for data. It is to establish the data sockets... so, no ServerSocket, means no data sockets, means no communications.

Henry


So considering the simplest chat program that is two clients in two pc. This two clients have to implement ServerSocket in both end and they are listening each other for connection request. Is this right ?

And if there is a server between this two clients then also those two clients have to implement ServerSocket for any connection request from server. Is this right ?
 
Muztaba Hasanat
Ranch Hand
Posts: 50
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:It's possible that you have decided that the purpose of a chat application is to allow two people to chat. And I suspect you haven't noticed another requirement, namely that the two people need to be able to find each other first. How do you plan to do that?


Thanks for the reply. I am assuming a simple chat program, that there is only two client in two pc. They will communicate.

What is my thought for multi user program where two client do not know there address then I can place a server. First a client will communicate with the server, then the server will give the address of the desire client
. After that client will establish connection with the desire client.
 
Henry Wong
author
Posts: 23958
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

Muztaba Hasanat wrote:
So considering the simplest chat program that is two clients in two pc. This two clients have to implement ServerSocket in both end and they are listening each other for connection request. Is this right ?



In a simple peer to peer setup, then yes, one of the clients have to implement the ServerSocket. The other one can just be an initiator, and make the connection request to the ServerSocket, which will accept the connections.

If you like, it is possible to make both sides be both an acceptor and initiator, but it is not required. In fact, this is common, as most peer to peer setups can get complicated, and it is easier, if any peer can initiate to any other peer.

Muztaba Hasanat wrote:
And if there is a server between this two clients then also those two clients have to implement ServerSocket for any connection request from server. Is this right ?



In theory, yes. In practice, this is not common. In general, with setup with a server, the server is generally the acceptor, and all clients are initiators (meaning no ServerSocket).

Henry
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic