I'm trying to build a chat application with Java server and JS client. It's ok but
when I try to send an image from the client with base64 format, the server closed with the reason TOO BIG.
So how can I increase the transport limit? Or if there's another way to send an image to the server,
please tell me. Thanks. The code below:
The server:
@ServerEndpoint(value = "/chat/{username}", decoders = MessageDecoder.class, encoders = MessageEncoder.class)
public class ChatEndpoint {
private Session session;
private static final Set<ChatEndpoint> chatEndpoints = new CopyOnWriteArraySet<>();
private static HashMap<String, String> users = new HashMap<>();
static boolean checkAll = true;
static String userAll;
@OnOpen
public void onOpen(Session session, @PathParam("username") String username) throws IOException, EncodeException {
...
}
@OnMessage
public void onMessage(Session session, Message message) throws IOException, EncodeException, SQLException, ClassNotFoundException {
broadcast(message);
}
...
private static void broadcast(Message message) throws IOException, EncodeException {
chatEndpoints.forEach(endpoint -> {
synchronized (endpoint) {
try {
endpoint.session.getBasicRemote()
.sendObject(message);
//System.out.println("end point "+endpoint.session.getUserProperties().get("username"));
} catch (IOException | EncodeException e) {
e.printStackTrace();
}
}
});
}
And the client:
ws = new WebSocket("ws://" + document.location.host + "/Project1.3/chat/" + username);
ws.onMessage = ...
...
function send(to) {
var content = document.getElementById("message").value;
$('#message').val('');
var json = JSON.stringify({
"from":username,
"to":to,
"content":content,
"type":"text"
});
ws.send(json);
}