TCP Multicasting?

Hello, I am in the process of writing a chat client, I want to use TCP, and so far I can get a client to connect and talk to the server, however when a client sends data, I only know how to send the data back to the client that sent it as I use threads...

Ive been searching for quite some time, and the closest I came to was this...

http://java.sun.com/docs/books/tutorial/networking/datagrams/broadcasting.html

However it appears that it is UDP...

Whats the best way to do this? Should I use Datagram packets? Right now I handle clients using threads, so if anyone could give me any advice ide appreciate it!

[641 byte] By [Evilsantaa] at [2007-11-26 18:50:41]
# 1

In a typical and common implementation of chat server, multiple client connections run as multiple threads and they do their io watching cue(s) from the server, or, by simple looping.

An example of looping implementation can be found in http://examples.oreilly.com/javacook2/ at the network/chat directory of the downloadable jar file.

hiwaa at 2007-7-9 6:24:44 > top of Java-index,Core,Core APIs...
# 2

Thanks for the reply, I am fairly new to OOP, but I think it will be worth my time to go with the thread approach. All I am lost with his how to have a thread get something from a client, then have all the server send the data to all the other client threads...

Normally I can figure things out for myself, however I am not even sure on the design approach I should be taking.

Evilsantaa at 2007-7-9 6:24:44 > top of Java-index,Core,Core APIs...
# 3

> Thanks for the reply, I am fairly new to OOP, but I

> think it will be worth my time to go with the thread

> approach. All I am lost with his how to have a thread

> get something from a client, then have all the server

> send the data to all the other client threads...

>

> Normally I can figure things out for myself, however

> I am not even sure on the design approach I should be

> taking.

See the code for the ChatServer class and its inner class ChaHandler contained in the downloadable jar file mentioned in the reply #1. In the ChatHandler.boadcast() method, you can find a simple loop sending data to all the clients currently connected. And the broadcast() method is called from within run() method of each ChatHandler thread.

hiwaa at 2007-7-9 6:24:44 > top of Java-index,Core,Core APIs...
# 4
Excellent thanks much! I got it working.
Evilsantaa at 2007-7-9 6:24:44 > top of Java-index,Core,Core APIs...