Guest User

Untitled

a guest
Jul 22nd, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. /**
  2. * @(#)OutputServer.java
  3. *
  4. * OutputServer application
  5. *
  6. * @author
  7. * @version 1.00 2010/1/17
  8. */
  9. import java.net.*;
  10. import java.io.*;
  11. public class OutputServer implements Runnable{
  12.  
  13. private ServerSocket s;
  14. private Socket c;
  15.  
  16. public static void main(String[] args) {
  17. OutputServer mainClass = new OutputServer();
  18. }
  19.  
  20. public OutputServer() {
  21. try {
  22. /* Open a server socket */
  23. s = new ServerSocket(5555);
  24. /* Create a bridge from server to client */
  25. c = null;
  26. try {
  27. c = s.accept();
  28. new Thread(new OutputServer()).start();
  29. } catch (IOException ee) {
  30. System.err.print("Connection could not establish correctly.");
  31. System.exit(-1);
  32. }
  33. } catch (IOException e) {
  34. System.err.print("Trouble opening socket on port 5555, port in use?");
  35. System.exit(-1);
  36.  
  37.  
  38. }
  39. }
  40.  
  41. public void run(){
  42. try {
  43. PrintWriter out = new PrintWriter(
  44. c.getOutputStream(), true);
  45. BufferedReader in = new BufferedReader(
  46. new InputStreamReader(
  47. c.getInputStream()));
  48.  
  49. String inLine, outLine;
  50.  
  51. MainProtocol mainProtocol = new MainProtocol();
  52. outLine = mainProtocol.processInput(null);
  53. out.println(outLine);
  54.  
  55. while ((inLine = in.readLine()) != null) {
  56. outLine = mainProtocol.processInput(inLine);
  57. out.println(outLine);
  58. if (outLine == "Exit.") {
  59. break;
  60. }
  61. }
  62. out.close();
  63. in.close();
  64. c.close();
  65. } catch (Exception e) {
  66. System.err.print(e.getStackTrace());
  67. }
  68. }
  69. }
Add Comment
Please, Sign In to add comment