• Post Reply Bookmark Topic Watch Topic
  • New Topic

Multiple Client and one Server

 
Natesan Prabhakaran
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.
 
Rob Spoor
Sheriff
Posts: 20817
68
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();

 
Ulf Dittmer
Rancher
Posts: 42970
73
  • 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: 20817
68
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!