1

I'm trying to send a base64 encoded string (converted from a image) via websocket and this is working fine for me with a javascript client.

But if I use a java client (@clientEndPoint) instead, onMessage function is triggered once and the websocket connection immediately closes down. No errors.

Again, I tried sending plain strings from the server and the java client functions properly. But just not with base64 encoded strings.

I'm using Tomcat 7.0.69 and below are the code snippets:

Server End Point:

if (imageToBeSend != null) {
   encodedImage = new sun.misc.BASE64Encoder().encode(imageToBeSend);
   session.getBasicRemote().sendText(encodedImage);
   }

Java client:

@ClientEndpoint
public class SomeClass {
    CountDownLatch latch = new CountDownLatch(1);
    private Session session;
    String msg;

    @OnOpen
    public void open(Session session) {
        this.session = session; 
        //some stuff
    }

    @OnClose
    public void close(Session session) {
        System.out.println("Closing the connection");
    }

    @OnError
    public void onError(Throwable error) {
        System.out.println("!!!ERROR!!!!!" + error);
        error.printStackTrace();
    }

    @OnMessage
    public void handleMessage(String message, Session session) throws IOException {
     System.out.println("got the json string  "+message.length());
     // more stuff
    }

Here the handle message is invoked one time and the corresponding sysout is printed and then immediately onClose is invoked. onError is never invoked.

avgs
  • 21
  • 7

0 Answers0