public Client() { try { Socket socket = new Socket("192.168.1.34", PORT); exec.execute(new SendMsg(socket)); System.out.println("[" + socket.getInetAddress() + "] ' Joining ... "); BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream())); String msg; while ((msg = br.readLine()) != null) { System.out.println(msg); } } catch (IOException e) { } }
private void sendDataTcp(int dataServerPort, String xmlEmployees) throws IOException { ServerSocket serverSocket = new ServerSocket(dataServerPort); serverSocket.setSoTimeout((int) SECONDS.toMillis(100)); boolean isTimeExpired = false; while (!isTimeExpired) { try { Socket socket = serverSocket.accept(); // Blocking call! serialize(xmlEmployees, socket.getOutputStream()); socket.close(); } catch (SocketTimeoutException e) { System.out.println( "[WARNING] ----------------------------------------- \n" + "[WARNING] Waiting time expired... Socket is closed."); isTimeExpired = true; continue; } } serverSocket.close(); }
public void run() { System.out.println("starting " + threadname + " run method on port " + SudokuServer.PORT); System.out.flush(); try { Socket sock = new Socket(hostname, SudokuServer.PORT); PrintWriter dos = new PrintWriter(sock.getOutputStream()); BufferedReader dis = new BufferedReader(new InputStreamReader(sock.getInputStream())); dos.println(testcase); dos.flush(); String response = dis.readLine(); System.out.println( "Client " + threadname + " sent: " + testcase + " received response:" + response); dos.close(); dis.close(); synchronized (sc) { sc.result = response; } } catch (Exception e) { e.printStackTrace(); } System.out.println("finishing " + threadname + " run method"); }
public void run() { try { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw = new PrintWriter(socket.getOutputStream(), true); String msg; while (true) { msg = br.readLine(); pw.println(msg); if (msg.trim().equals("-quit")) { pw.close(); br.close(); exec.shutdownNow(); break; } } } catch (Exception e) { e.printStackTrace(); } }