Advertisement
Guest User

FMSS

a guest
Oct 4th, 2015
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. import java.net.*;
  2. import java.io.*;
  3.  
  4. import org.slf4j.Logger;
  5. import org.slf4j.LoggerFactory;
  6. import java.sql.Timestamp;
  7. import java.util.Date;
  8.  
  9. public class FixedMessageSequenceServer extends Thread /* added in e T just now*/{
  10.  
  11. private static final Logger logger = LoggerFactory.getLogger("FixedMessageSequenceServer");
  12.  
  13. public static void main(String[] args) throws IOException , InterruptedException {
  14.  
  15. logger.debug("This is a DEBUG message in Server ");
  16. int jokeLocation;
  17.  
  18.  
  19.  
  20.  
  21. ServerSocket serverSocket = null;
  22.  
  23. try {
  24. serverSocket = new ServerSocket(4444);
  25. } catch (IOException e) {
  26. System.err.println("Could not listen on port: 4444.");
  27. System.exit(1);
  28. }
  29.  
  30. Socket clientSocket = null;
  31. try {
  32. clientSocket = serverSocket.accept();
  33.  
  34. } catch (IOException e) {
  35. System.err.println("Accept failed.");
  36. System.exit(1);
  37. }
  38.  
  39. PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);
  40. BufferedReader in = new BufferedReader(
  41. new InputStreamReader(
  42. clientSocket.getInputStream()));
  43. String inputLine, outputLine;
  44. FixedMessageSequenceProtocol kkp = new FixedMessageSequenceProtocol(1);
  45.  
  46. outputLine = kkp.processInput(null); // ??????????????????
  47. out.println(outputLine);
  48.  
  49.  
  50. try{
  51. while ((inputLine = in.readLine()) != null) {
  52. System.out.println(inputLine);
  53. outputLine = kkp.processInput(inputLine);
  54. out.println(outputLine);
  55. if (outputLine.equals("Bye."))
  56. break;
  57. }
  58. }catch(SocketException so) {
  59.  
  60.  
  61. try {
  62. String[] command = {"C://Users//Adel//Dropbox//Thesis//Misc_Stuff//Java_Code//FixedMessageSequence_code//ClientBatchFile.bat"}; //args[0] ... CreateTexts
  63. ProcessBuilder pb = new ProcessBuilder(command);
  64. pb.redirectErrorStream(true);
  65. Process exec = pb.start();
  66.  
  67.  
  68.  
  69. BufferedReader br = new BufferedReader(new InputStreamReader(exec.getInputStream()));
  70. String text = null;
  71. while ((text = br.readLine()) != null) {
  72. System.out.println(text);
  73. }
  74.  
  75. System.out.println("Process exited with " + exec.waitFor());
  76. } catch (IOException exp ) { /*InterruptedException */
  77. exp.printStackTrace();
  78. }
  79. }
  80.  
  81.  
  82.  
  83. out.close();
  84. in.close();
  85. clientSocket.close();
  86. serverSocket.close();
  87. }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement