• 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
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

Client-Client Communication

 
Ranch Hand
Posts: 112
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 112
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic