i can send from client side to WebFlux and see the string bug how can i send back to client side and that the client side be able to parse it is something i can’t figure out .
this is what have as server using java spring WebFlux ;
public Mono<Void> handle(WebSocketSession session) {
Flux<WebSocketMessage> output2 = session.receive()
.doOnNext(message -> {
logger.info("Recived from client:"+message.getPayloadAsText());
})
.map(value -> session.textMessage("Echo " + value.getPayloadAsText()));
return session.send(output2);
}
And this is the client :
var WebSocket = WebSocket || window.WebSocket || window.MozWebSocket;
_stringConvertToArray = function(strData) {
if (!strData)
{
return null;
}
var arrData = new Uint16Array(strData.length);
for (var i = 0; i < strData.length; i++) {
arrData[i] = strData.charCodeAt(i);
}
return arrData;
};
_stringConvertToUint8Array = function (strData) {
// View the byte buffer as an array of 8-bit unsigned integers
var arrData = new Uint8Array(strData.length);
for (var i=0;i<strData.length;++i) {
arrData[i] = strData.charCodeAt(i);
}
// Log the binary array
console.log("SEND ARRAY BUFFER: " + arrData.buffer);
return arrData;
};
var connection = new WebSocket("ws://localhost:8001/test");
connection.binaryType = "arraybuffer";
connection.onopen = function(evt) {
console.log("Send Binary WS was opened.");
};
connection.onmessage = (function(evt) {
console.log(evt.currentTarget.binaryType);
var binaryUint8 = new Uint8Array(evt.data);
var binaryStr = '';
for (var i = 0; i < binaryUint8.length; i++) {
binaryStr += String.fromCharCode(binaryUint8[i]);
}
console.log("recived from server:"+binaryStr);
connection.onerror = function(evt) {
//this.m_loginObj.serverofflineLabel = 180;
conosle.log("connection Error was fired");
};
connection.onclose = function(evt) {
conosle.log("connection websocket instance closed.");
connection = null;
};
})
var sendMassage = function(reqJson)
{
if (this.connection.readyState == WebSocket.OPEN)
{
var buf = reqJson;//Encode(reqJson);
var binary = this._stringConvertToUint8Array(buf);
this.connection.send(binary.buffer);
}
else
{
var warningStr = "send binary websocket instance wasn't ready...try again in few seconds";
console.log(warningStr);
this.init();
}
};
in the function : connection.onmessage i keep getting empty data .