The moose likes Sockets and Internet Protocols and the fly likes Client-Client Communication Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Reply Bookmark "Client-Client Communication" Watch "Client-Client Communication" New topic
Author

Client-Client Communication

Pavan Kumar Dittakavi
Ranch Hand

Joined: Feb 12, 2011
Posts: 76
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.


Thanks,
Pavan.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 3144
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: 76
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: 3144
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.
 
 
subject: Client-Client Communication
 
Threads others viewed
how an Applet can make a socket on local port
Socket Sending and Recieving at same Time?
Open ports in a huge web application.
socket programming on 2 ports
EJB listening on a client socket for callbacks
IntelliJ Java IDE

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture