package examples; import java.net.*; import java.io.*; import java.util.*; public class MyClients { public static void main(String[] args) { List list = new LinkedList(); for(int i = 0; i < 100; i++) { Client c = new Client("Client" + i); list.add(c); c.start(); } } private static class Client extends Thread { private String name; private Socket conn; private PrintWriter toServer; private Scanner fromServer; private static String[] phrases = { "You had me at hello", "The force is strong with this one", "You can't handle the truth", "There is no spoon", "Gosh!", "You ever danced with the devil in the pale moonlight", "1.21 Gigawatts!!!", "I'm mad as hell, and I'm not going to take it anymore", "They're heeerrrre", "If the sun comes up tomorrow, it will only be because of men of good will", "Every man gets one chance to do something great. This is yours, kid!", "Negative, Ghostrider, the pattern is full.", "I feel the need.... the need for speed", "I don't even know what a quail looks like", "I have got to get me one of these!", "Bumblebee Tuna, Bumblebee Tuna" }; private static Random rand = new Random(); public Client(String name) { this.name = name; } public void run() { try { System.out.print("Connecting to server...."); conn = new Socket(InetAddress.getByName("selenium.cs.pitt.edu"), 3459); System.out.println("done"); fromServer = new Scanner(conn.getInputStream()); toServer = new PrintWriter(conn.getOutputStream()); String line; int count = rand.nextInt(30); for(int i = 0; i < count; i++) { //send to server toServer.println(phrases[rand.nextInt(phrases.length)]); toServer.flush(); //read response from server line = fromServer.nextLine(); System.out.println(name + ": " + line); } toServer.println("exit"); toServer.flush(); fromServer.close(); toServer.close(); conn.close(); } catch(IOException ioe){ioe.printStackTrace();} } } }