• 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
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Multiple Client and one Server

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 22457
121
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 43026
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 22457
121
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic