• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

chat program

 
Ranch Hand
Posts: 264
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi

i try to do a chat program

i have the server and the client...

the server allow many client to connect to it

server code


client code


work fine...

when a client send a message to the client, i would like that all client receive it...

what is the correct way to do it?
create a socket for every client and server connect to it?


thanks
 
Bartender
Posts: 1844
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmm..

Sockets are not really beginner's level stuff. I'm moving this to our Sockets and INternet Protocols forum.
 
mark smith
Ranch Hand
Posts: 264
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i would like to know how in a application client/server how we send received message to all client?
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One way to do this would be to have the Server keep a list of all clients. You would probably maintain a list of sockets to each of the clients. Then you will iterate through the list of sockets and send the message to each one. Let us know how things work out with this, or if you think of anything yourself.

Layne
 
Ranch Hand
Posts: 367
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have the same question. Is it really a good idea to have opened sockets to all clients? I'm closing mine so there is my problem. I don't know when the Applet in this case have closed. If you come up with any solutions to this I would be glad the see it.

// Mathias
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want to be able to communicate with the client, it seems to me that you have to have an open socket connection. Unless you have some way to reopen the socket with the same client, then you will need to maintain an open connection.

Layne
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In my work, the client is a browser and the server is a big AIX box. To send messages from the server to the client we reverse the roles ... the browser becomes the server and the AIX box becomes the client.

The browser has an applet that holds a ServerSocket open. At logon the browser tells the AIX box its ServerSocket address and the AIX box keeps a list of all the applet servers. To broadcast a message to a user, the AIX box looks up the addres for that user's applet, opens a socket and sends the message. To send to all users, it repeats open-send-close for each registered applet.

Does that sound interesting?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic