イメージをjavaのbytebufferに変換し、javaのwebsocketを通してクライアントに送信します。以下のような Java側の外観:クライアント側でByteBufferをHTMLのImageに変換するには
@OnOpen
public void onOpen(Session sessions) {
String fileName = sessions.getUserPrincipal().getName() + ".png";
File fi = new File("/Users/shilu/MyProject/Chat/Photo/" + fileName);
byte[] fileContent = null;
try {
fileContent = Files.readAllBytes(fi.toPath());
ByteBuffer buf = ByteBuffer.wrap(fileContent);
sessions.getBasicRemote().sendBinary(buf);
} catch (IOException e) {
e.printStackTrace();
}
}
は、私はちょうどこのようにそれを得る:
gp.onmessage = function(evt) {
var msg = evt.data;
};
を今どのように私はhtmlの...でその画像を表示していますか?画像のsrc属性にevt.dataを入れて
[バイト配列から設定のIMG SRC]の可能な重複(http://stackoverflow.com/questions/30129486/set- img-src-from-byte-array) – DimaSan
evtをバイト配列に変換するには? –