如何在Java套接字中提供本地图像路径?

时间:2019-03-04 07:22:19

标签: java serversocket

  public void run() throws IOException {
    server = new ServerSocket(port) {
      protected void finalize() throws IOException {
        this.close();
      }
    };
    System.out.println("Server is running on port 12345");

    while (true) {
      // accepts a new client
      Socket client = server.accept();

      // get nickname of newUser
      String nickname = (new Scanner ( client.getInputStream() )).nextLine();
      nickname = nickname.replace(",", ""); //  ',' use for serialisation
      nickname = nickname.replace(" ", "_");
      System.out.println("New Client: \"" + nickname + "\"\n\t     Host:" + client.getInetAddress().getHostAddress());

      // create new User
      User newUser = new User(client, nickname);

      // add newUser message to list
      this.clients.add(newUser);

      // Welcome msg
      newUser.getOutStream().println(
          "<img src='https://www.kizoa.fr/img/e8nZC.gif' height='42' width='42'>"
          + "<b>Welcome</b> " + newUser.toString() +
          "<img src='https://www.kizoa.fr/img/e8nZC.gif' height='42' width='42'>"
          );

      // create a new thread for newUser incoming messages handling
      new Thread(new UserHandler(this, newUser)).start();
    }
  }

为img标签设置src属性https://www.kizoa.fr/img/e8nZC.gif很好。但是我想将本地图像作为img的属性,以便客户端可以看到它。像<img src='e8nZC.gif' height='42' width='42'>。我该怎么办?

0 个答案:

没有答案