aspose file tools
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: 95

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: 5895
    
    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: 95

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: 5895
    
    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://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Client-Client Communication
 
Similar Threads
Socket Sending and Recieving at same Time?
how an Applet can make a socket on local port
Open ports in a huge web application.
socket programming on 2 ports
EJB listening on a client socket for callbacks