コード例 #1
0
  /** Set up loop checking for messages from the server */
  public static void receiveFromServer() {
    while (true) {
      String message = null;
      try {
        message = inFromServerBuffer.readLine();
      } catch (IOException e) {
        System.err.println("inFromServerBuffer unable to read from server");
      }

      if (message != null) {
        try {
          clientBoundMessages.put(message);
        } catch (InterruptedException e) {
          System.err.println(
              "clientBoundMessages buffer was unable to receive message: " + message);
        }
      }
    }
  }
コード例 #2
0
  /** Set up loop checking to see if there are messages to be sent to the server */
  public static void sendToServer() {
    while (true) {

      String message = null;
      try {
        message = (String) serverBoundMessages.get();
      } catch (InterruptedException e) {
        System.err.println("serverBoundMessages was unable to give us message");
      }

      if (message != null) {
        try {
          outToServerStream.writeBytes(message + "\n");
          outToServerStream.flush();
          message = null;
        } catch (IOException e) {
          System.err.println("outToServerStream unable to send message to the server.");
        }
      }
    }
  }