Пример #1
0
 @Override
 public void sendMsg(Messages msg) {
   try {
     if (!msg.getEncryptedStatus()) {
       msg.EncryptedMe(SingletonEncryptionMethod.getInstance());
     }
     os.writeObject(msg);
     os.flush();
   } catch (IOException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
 }
Пример #2
0
  public ConnectedClients(Socket inputSocket) {
    clientSocket = inputSocket; // initialization of connections.
    // super.init(clientSocket);
    Object msg = null;

    try {

      os = new ObjectOutputStream(clientSocket.getOutputStream());
      in = new ObjectInputStream(clientSocket.getInputStream());
      CommonUtils.PrintMe("invoke themethod to create a instance of connected client");
      msg = in.readObject();

    } catch (ClassNotFoundException | IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      return;
    }

    Messages firstMsg = (Messages) msg;
    CommonUtils.PrintMe(
        "the server get the frist  message from the new client:"
            + firstMsg.getContent()
            + "是否加密:"
            + firstMsg.getEncryptedStatus()
            + "消息类型:"
            + firstMsg.getMsgType());
    firstMsg.DecryptedMe(
        SingletonEncryptionMethod.getInstance()); // use ROT13 decrypt the incomming Msg

    clientName = firstMsg.getSenderName();
    clientIp = firstMsg.getSenderIp();

    firstMsg.printMsg();

    CommonUtils.PrintMe(
        "the instance of client send a  message:---" + firstMsg.getContent() + "---");
  }