Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

serverSocket

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can a server socket send messages like a normal Socket?

At the moment I have a client (of type Socket) which can send / receive messages by writing to / reading from a stream.

I have a server which, when a client connects, starts a new thread which then deals with communication to / from that client.

I want the server to be able to send urgent messages to ALL clients that are currently logged on but have no idea how to do this! Any suggestions?

J
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One way is to reverse roles so the clients become servers and the server becomes a client. Each client starts up a server socket and "registers" with the server at logon by sending the address. When the server wants to blast a message it iterates through the registered clients, does connect, send, disconnect. This is not instantaneous. If you have lots of clients it may take a while, especially if some of them time out or fail in unclean ways.
 
It's a tiny ad only because the water is so cold.
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic