wood burning stoves 2.0*
The moose likes Sockets and Internet Protocols and the fly likes Client-Client Communication Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Client-Client Communication" Watch "Client-Client Communication" New topic
Author

Client-Client Communication

Pavan Kumar Dittakavi
Ranch Hand

Joined: Feb 12, 2011
Posts: 104

Hi All,


Im fairly new to this socket world, so googled and came across a simple client server mechanism. Here is the link. So, the server waits for the client to connect to it. Now, I have a query. How can I modify the code so that it would help me simulate chating with some other person?. Cant we achieve the same without using the Server [ Server Socket ]?.


Thanks.
Pavan.

Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

There has to be a server listening for you to connect to. (Or an open DatagramSocket that you can send to if you're doing UDP instead of TCP, but it's the same principle.)
Pavan Kumar Dittakavi
Ranch Hand

Joined: Feb 12, 2011
Posts: 104

Thanks for the response Jeff. But if Im planning to design a chat application in which say two users[ can be many as we know ] can chat, how can that be done? Please shed some info on the same.

Thanks,
Pavan.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

The way most chat applications work is that there's a server between the two clients. When you chat with your friends on Yahoo or Skype or Google chat, you each establish a connection to the server, and it relays the messages between you. Note that the server is a server in two different capacities:

1) At the socket level, it is opening the ServerSocket (or other API equivalent) and your chat clients are creating socket connections to that server socket.

2) At the application level, it serves as the relay host that A) has a public IP address and B) knows about accounts and who's online.

It is possible to create a peer-to-peer chat client that doesn't need a server in the sense of #2 above, but for the TCP connection, one end still has to open the ServerSocket as in #1 above. Also note that this approach only works if the server has a public IP address (or receives port forwarding form one) or if both client and server are on the same LAN.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Client-Client Communication
 
Similar Threads
Socket Sending and Recieving at same Time?
socket programming on 2 ports
EJB listening on a client socket for callbacks
Open ports in a huge web application.
how an Applet can make a socket on local port