public static void main(String[] args) throws Exception { Properties properties = new Properties(); FileInputStream propFile = new FileInputStream("store.properties"); properties.load(propFile); final String id = properties.getProperty("ID"); final String placeForFiles = properties.getProperty("FilePlace"); int servicePort = Integer.parseInt(properties.getProperty("ServicePort")); int tcpPort = Integer.parseInt(properties.getProperty("TCPPort")); String ksName = properties.getProperty("KeyStore"); KeyStore ks = KeyStore.getInstance(properties.getProperty("KeyStoreType")); char[] password = properties.getProperty("Password").toCharArray(); char[] passwordForKey = properties.getProperty("PasswordForKey").toCharArray(); ks.load(new FileInputStream(ksName), password); KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509"); kmf.init(ks, passwordForKey); SSLContext context = SSLContext.getInstance("TLS"); context.init(kmf.getKeyManagers(), null, null); SSLServerSocketFactory ssf = context.getServerSocketFactory(); SSLServerSocket serverSocket = (SSLServerSocket) ssf.createServerSocket(tcpPort); ServiceThread serviceThread = new ServiceThread(servicePort, id); serviceThread.start(); while (!serverSocket.isClosed()) { ClientThread client = new ClientThread(placeForFiles); SSLSocket socket = (SSLSocket) serverSocket.accept(); socket.startHandshake(); client.setSocket(socket); client.start(); } }
public void execute() { ServerSocket serverSocket = null; Socket socket = null; try { System.out.println("서버 준비 중..."); serverSocket = new ServerSocket(9999); ClientThread clientThread = null; while (true) { System.out.println("클라이언트 대기 중..."); socket = serverSocket.accept(); clientThread = new ClientThread(this, socket); clientThread.start(); clients.add(clientThread); } } catch (Exception e) { e.printStackTrace(); } finally { try { serverSocket.close(); } catch (Exception e) { } } }
@Override public Map<String, Set<String>> getAttributes(String identifier) throws Exception { if (LOG.isInfoEnabled()) LOG.info("Retrieving attributes for user=" + identifier); // all attributes (name, description) retrieved from esg_ats.xml and esgf_ats_static.xml final Map<String, String> attributes = registryService.getAttributes(); // always request no attributes - i.e. ALL attributes final Set<String> requestedAttributeTypes = new HashSet<String>(); // global list used to avoid double invocations (if more than one attribute is served by the // same attribute service) final List<String> _urls = new ArrayList<String>(); // list of client threads, one for each remote attribute service to be queried List<ClientThread> threads = new ArrayList<ClientThread>(); // loop over attribute types for (final String atype : attributes.keySet()) { final List<URL> aservices = registryService.getAttributeServices(atype); // loop over attribute services for that type for (final URL url : aservices) { String _url = url.toString(); // don't query the same URL twice if (!_urls.contains(_url)) { _urls.add(_url); ClientThread clientThread = new ClientThread(url, identifier, requestedAttributeTypes); clientThread.start(); threads.add(clientThread); } } } // wait for all threads to finish for (Thread thread : threads) { thread.join(); } // global user attributes map final Map<String, Set<String>> map = new HashMap<String, Set<String>>(); // combine all retrieved SAML attributes for (ClientThread thread : threads) { final SAMLAttributes samlAttributes = thread.getSAMLAttributes(); final Map<String, Set<String>> _map = samlAttributes.getAttributes(); for (String key : _map.keySet()) { for (String value : _map.get(key)) { if (StringUtils.hasText(value)) { if (!map.containsKey(key)) { map.put(key, new HashSet<String>()); } map.get(key).add(value); } } } } return map; }
Server() { // Maak een socket aan om op clients te wachten ServerSocket serverSocket = null; try { serverSocket = new ServerSocket(SERVER_PORT); System.out.println("Socket aangemaakt"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } // Wacht op binnenkomende client connectie requests. while (true) { try { Socket socket = serverSocket.accept(); verbonden.add(socket); System.out.println(verbonden.size()); // Als er een verbinding tot stand is gebracht, start een nieuwe // thread. ClientThread ct = new ClientThread(socket); System.out.println("Verbinding tot stand gebracht met client!"); ct.start(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } // start de thread en roept run() aan. Gebruik hier niet // run(): dan wordt de code in de huidige thread gedraaid. } }
public static void main(String[] args) { Channel channel = new Channel(5); channel.startWorkers(); ClientThread alice = new ClientThread("Alice", channel); ClientThread bobby = new ClientThread("Bobby", channel); ClientThread chris = new ClientThread("Chris", channel); alice.start(); bobby.start(); chris.start(); try { Thread.sleep(5000); } catch (InterruptedException e) { } alice.stopThread(); bobby.stopThread(); chris.stopThread(); channel.stopAllWorkers(); }
public void creaClient() { try { clientSocket = new Socket(hostname, port); // ISTANZIO CLIENT SOCKET } catch (IOException e) { e.printStackTrace(); } clientThread = new ClientThread( clientSocket, this); // nuovo clientThread, gli passo il client socket e il client main clientThread.start(); Platform.runLater( new Runnable() { @Override public void run() { clientController.clientConnectButton.setDisable(true); } }); }
public ChatClient(Subject server, Socket socket) throws IOException { this.server = server; counter++; number = counter; this.socket = socket; // run new thread for listening server System.out.println("New ChatClient #" + number + " created"); inputStream = socket.getInputStream(); outputStream = socket.getOutputStream(); // TODO получение имени клиента вставить здесь // authorize(); clientThread = new ClientThread(); clientThread.start(); }
public void start() { keepGoing = true; /* create socket server and wait for connection requests */ try { // the socket used by the server ServerSocket serverSocket = new ServerSocket(port); // infinite loop to wait for connections while (keepGoing) { // format message saying we are waiting display("Server menunggu koneksi Client pada port " + port + "."); Socket socket = serverSocket.accept(); // accept connection // if I was asked to stop if (!keepGoing) break; ClientThread t = new ClientThread(socket); // make a thread of it al.add(t); // save it in the ArrayList t.start(); } // I was asked to stop try { serverSocket.close(); for (int i = 0; i < al.size(); ++i) { ClientThread tc = al.get(i); try { tc.sInput.close(); tc.sOutput.close(); tc.socket.close(); } catch (IOException ioE) { // not much I can do } } } catch (Exception e) { display("Exception closing the server and clients: " + e); } } // something went bad catch (IOException e) { String msg = sdf.format(new Date()) + " Exception on new ServerSocket: " + e + "\n"; display(msg); } }
/** * Runs the client threads in the parallel test. * * @param clients The threads to run. * @return The time taken to run the threads. * @throws InterruptedException if a thread is interrupted. */ private double runClients(List<ClientThread> clients) throws InterruptedException { Date testStart = new Date(); // Execute threads. for (ClientThread client : clients) { client.start(); } // Block until clients are done. boolean isComplete = false; while (!isComplete) { isComplete = true; for (ClientThread client : clients) { isComplete = isComplete && !client.isAlive(); } // Prevent busy wait. if (!isComplete) { Thread.sleep(500); } } Date testEnd = new Date(); return testEnd.getTime() - testStart.getTime(); }
public void run() { try { ServerSocket serverSocket = new ServerSocket(7497); // infinite loop to wait for connections while (true) { log.info("Server waiting for Clients on port " + 7497); Socket socket = serverSocket.accept(); // accept connection log.info( " Connection Received from " + socket.getInetAddress() + " on port " + socket.getPort() + " to port " + socket.getLocalPort() + " of " + socket.getLocalAddress()); sInput = new DataInputStream(socket.getInputStream()); sOutput = new DataOutputStream(socket.getOutputStream()); MessageSender.instance.setup(sOutput); ClientThread t = new ClientThread(sInput); t.start(); // int version = sInput.read(); // log.info(version); write("76".getBytes()); // Send Server Id write("Test Time".getBytes()); // Send Test Time // int ClientId = sInput.read(); //Client Id // log.info(ClientId); } } catch (Exception e) { log.warn(e); } }
private void runCoreThreads() { serverThread.start(); clientThread.start(); }
/** * Core benchmark code. Connect. Initialize. Run the loop. Cleanup. Print Results. * * @throws Exception if anything unexpected happens. */ public void runBenchmark() throws Exception { log.info(HORIZONTAL_RULE); log.info(" Setup & Initialization"); log.info(HORIZONTAL_RULE); final int cidCount = 128; final long[] lastRid = new long[cidCount]; for (int i = 0; i < lastRid.length; i++) { lastRid[i] = 0; } // connect to one or more servers, loop until success connect(); log.info(HORIZONTAL_RULE); log.info("Starting Benchmark"); log.info(HORIZONTAL_RULE); // print periodic statistics to the console benchmarkStartTS = System.currentTimeMillis(); schedulePeriodicStats(); // Run the benchmark loop for the requested duration // The throughput may be throttled depending on client configuration log.info("Running benchmark..."); BigTableLoader partitionedLoader = new BigTableLoader( client, "bigp", (config.partfillerrowmb * 1024 * 1024) / config.fillerrowsize, config.fillerrowsize); partitionedLoader.start(); BigTableLoader replicatedLoader = new BigTableLoader( client, "bigr", (config.replfillerrowmb * 1024 * 1024) / config.fillerrowsize, config.fillerrowsize); replicatedLoader.start(); ReadThread readThread = new ReadThread(client, config.threads, config.threadoffset); readThread.start(); AdHocMayhemThread adHocMayhemThread = new AdHocMayhemThread(client); adHocMayhemThread.start(); List<ClientThread> clientThreads = new ArrayList<ClientThread>(); for (byte cid = (byte) config.threadoffset; cid < config.threadoffset + config.threads; cid++) { ClientThread clientThread = new ClientThread(cid, c, client, processor); clientThread.start(); clientThreads.add(clientThread); } final long benchmarkEndTime = System.currentTimeMillis() + (1000l * config.duration); while (benchmarkEndTime > System.currentTimeMillis()) { Thread.yield(); } replicatedLoader.shutdown(); partitionedLoader.shutdown(); readThread.shutdown(); adHocMayhemThread.shutdown(); for (ClientThread clientThread : clientThreads) { clientThread.shutdown(); } replicatedLoader.join(); partitionedLoader.join(); readThread.join(); adHocMayhemThread.join(); for (ClientThread clientThread : clientThreads) { clientThread.join(); } // cancel periodic stats printing timer.cancel(); shutdown.set(true); es.shutdownNow(); // block until all outstanding txns return client.drain(); client.close(); }
private void prepare(String serverIP) { mThread = new ClientThread(serverIP); mThread.start(); }