How do I send string to all clients that connected?
Ok I am sorry for disturbing again...
I have no idea how do I send string to all the clients that connected to the server
Client is made with flash (don't need do do anything here)
All I need to do is just to send string to the clients that's all.
So I've got 3 classes, one is main that listening for connections one is thread that does stuff to the client that connected and another thread that I want to work with
So yeah, I am just going to put the main class's code that I got:
Code:
import java.io.*;
import java.net.*;
import java.util.*;
public class Connector
{
public static ArrayList<Socket> ConnectionArray = new ArrayList<Socket>();
public static ArrayList<String> CurrentUsers = new ArrayList<String>();
public static void main(String[] args) throws IOException
{
try{//THIS IS STARTING THE CLASS THAT WE ARE WORKING ON----
serverMessage srMsg = new serverMessage();
Thread srMsgt = new Thread(srMsg);
srMsgt.start();
} catch(Exception E){ }
try
{
final int PORT = 2807;
ServerSocket SERVER = new ServerSocket(PORT);
System.out.println("Server launched.");
while(true)
{
Socket SOCK = SERVER.accept();
ConnectionArray.add(SOCK);
System.out.println("New user connected.");
ChatServer CHAT = new ChatServer(SOCK);
Thread X = new Thread(CHAT);
X.start();
}
}
catch(Exception X) {System.out.print(X);}
}
}
Soooo yeah... Waiting for replies!
Re: How do I send string to all clients that connected?
Have a list of clients. As each client connects to the server, save needed info about the client in a list.
Loop through the list and send the String to each client.
Re: How do I send string to all clients that connected?
Quote:
Originally Posted by
Norm
Have a list of clients. As each client connects to the server, save needed info about the client in a list.
Loop through the list and send the String to each client.
Thanks, I quite managed to figure it out, I forgot that I got
public static ArrayList<Socket> ConnectionArray = new ArrayList<Socket>();
array that holds it.
One thing I don't know how to check if someone disconnects..
Re: How do I send string to all clients that connected?
Quote:
how to check if someone disconnects..
Try doing some testing/debugging by having a couple of clients and have one disconnect. Print out all the values of the connections for the two clients and see what is different.