This week's book giveaway is in the General Computing forum.
We're giving away four copies of Learning Regular Expressions and have Ben Forta on-line!
See this thread for details.
Win a copy of Learning Regular Expressions this week in the General Computing 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Multiple Client and one Server  RSS feed

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am new to Socket programming. So, I don't know that is there a way to send a message from one server to multiple clients using TCP. When I search for it, came to know, it is possible only by using DatagramSocket (UDP). Is it not possible by using TCP? Please correct me.

Thanks.
 
Sheriff
Posts: 21462
96
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't send one single message to all clients at the same time. You can of course keep a reference to all clients and then send the same message to all clients separately. In pseudo code:
 
Natesan Prabhakaran
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Thanks for your valuable response.

Here is my code, I don't know, how to do using pseudo code.

Socket theclient = null;
ServerSocket serverSocket=null;
f = new File("E:/Examples/EVR.pdf");
filelength = f.length();

serverSocket = new ServerSocket(8888);
theclient = serverSocket.accept();
System.out.println("coming SendTotalPackets");
pout = new PrintWriter(theclient.getOutputStream(),true);
pout.println(filelength);
pout.flush();

 
Rancher
Posts: 42975
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might want to work through the client/server example of the Sun Java Tutorial: http://java.sun.com/docs/books/tutorial/networking/sockets/clientServer.html. That should make things clearer.
 
Rob Spoor
Sheriff
Posts: 21462
96
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, don't println() to a Socket. Ignore the message about the article being a legacy document - it's still relevant.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!