edit: im sure this is just something stupid that im missing eh?
This post has been edited by CrimsonAngel: 16 September 2011 - 01:57 PM




2 Votes
Posted 16 September 2011 - 01:43 PM
This post has been edited by CrimsonAngel: 16 September 2011 - 01:57 PM
Posted 16 September 2011 - 02:27 PM
CasiOo, on 16 September 2011 - 03:21 PM, said:
Posted 16 September 2011 - 03:36 PM
ArrayList<Connection> alSocket;
Random ran = new Random();
void sendTo5(String msg) {
// build an arrayList of int based on the number of connections I have
ArrayList<Integer> al = new ArrayList<Integer>();
// add an entry based on the number of user
for(int i = 0; i < alSocket.size(); ++i)
al.add(i);
// randomly select up to 5 connections
for(int i = 0; i < 5; i++) {
if(al.size() == 0) // if less than 5 clients
return;
int index = ran.nextInt(al.size()); // select random number
index = al.remove(index); // select and remove
Connection con = alSocket.get(index); // get a random connection
.... write msg to con.outputStream
}
}
Posted 16 September 2011 - 06:56 PM
pbl, on 16 September 2011 - 04:36 PM, said:
ArrayList<Connection> alSocket;
Random ran = new Random();
void sendTo5(String msg) {
// build an arrayList of int based on the number of connections I have
ArrayList<Integer> al = new ArrayList<Integer>();
// add an entry based on the number of user
for(int i = 0; i < alSocket.size(); ++i)
al.add(i);
// randomly select up to 5 connections
for(int i = 0; i < 5; i++) {
if(al.size() == 0) // if less than 5 clients
return;
int index = ran.nextInt(al.size()); // select random number
index = al.remove(index); // select and remove
Connection con = alSocket.get(index); // get a random connection
.... write msg to con.outputStream
}
}
Posted 17 September 2011 - 12:49 PM
Posted 17 September 2011 - 03:28 PM
public Server() throws IOException
{
System.out.println("Starting...");
Node = new ServerSocket(serverNumber);
System.out.println("Server UP, port " + serverNumber + " is open");
this.start();
(new Thread(new Client())).start();
}
public void run()
{
while(true)
{
try{
Socket client = Node.accept();
System.out.println("got connection " + client.getInetAddress());
//Connect c = new Connect(client);
aSockets[connections] = client;
connections++;
System.out.println("current connection number: " + connections);
if (connections == 9)
{
///todo code
class Connect extends Thread
{
ArrayList<ObjectInputStream> input;
ArrayList<ObjectOutputStream> output;
public Connect(){}
public Connect(Socket [] clientSocket)
{
//doesnt send anything if it doesnt have all 10 of the connections
// setting connections to 1 for testing
System.out.println("im in server side connections");
try{
//open streams
for(int i = 0; i < 9; i++)
{
input.add(new ObjectInputStream(clientSocket[i].getInputStream())) ;
output.add( new ObjectOutputStream(clientSocket[i].getOutputStream()));
}
}catch(Exception e){
try{
}catch(Exception ew)
{
System.out.println(ew.getMessage());
}
return;
}
this.start();
}
ArrayList<ObjectOutputStream> output = new ArrayList<ObjectOutputStream>();
ArrayList<ObjectInputStream> input = new ArrayList<ObjectInputStream>();
ArrayList <Socket> socket = new ArrayList<Socket>();
public void Client(){
collector.name = name;
}
public void run()
{
try {
// open a socket connection
//makes sure it has 9 connections before it continues
//if it doesnt have 9 connections it clears and checks again
while(socket.size() < 9)
{
for(int i = 0,j = 0; i < 10; i++, j++)
{
if(i == name)
{
j--;
continue;
}
socket.add(new Socket("net1" + i + ".utdallas.edu", 2000 + i));
// open I/O streams for objects
output.add(new ObjectOutputStream(socket.get(j).getOutputStream()));
input.add(new ObjectInputStream(socket.get(j).getInputStream()));
}
if(socket.size() < 9)
{
socket.clear();
output.clear();
input.clear();
}
}
Posted 17 September 2011 - 03:33 PM
Posted 17 September 2011 - 03:36 PM
Posted 17 September 2011 - 04:24 PM
Posted 17 September 2011 - 04:27 PM
Posted 17 September 2011 - 04:30 PM
This post has been edited by blackcompe: 17 September 2011 - 04:32 PM
