Forums Register Login

Multiple Client and one Server

+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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:
+Pie Number of slices to send: Send

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();

+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
Also, don't println() to a Socket. Ignore the message about the article being a legacy document - it's still relevant.
Just let me do the talking. Ahem ... so ... you see ... we have this tiny ad...
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 4840 times.
Similar Threads
protocols quary: need help
port details
How webserver handle multiple requests on a single port?
What is the meaning of data displayed by netstat -a
Why are write calls blocking?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 05:20:48.