tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jason Ricles <jgr...@alum.lehigh.edu>
Subject Websocket @OnMessage is never firing for binary messages only text
Date Tue, 18 Nov 2014 19:14:21 GMT
I am writing a websocket communication with the client and server
endpoints both in java code (using tomcat 7.0.53 as the web server)
When I send a text message using the
session.getbasicremote.sendText(String) method the @Onmessage function
is fired and everything. However I want to send binary data between
the websockets so thus have to use
session.getbasicremote.sendBinary(ByteBuffer). The code should then be
read within the following method,

@OnMessage
public void recieved(ByteBuffer byteBuffer)
{
    System.out.println(byteBuffer);
}

However the method is never fired when the message is sent (I debugged
through both remote debugging and print statements to verify that the
binary data is being sent also yes regular text does get sent through
this method when binary is switched to text). Does anyone have a clue
why this method is never being called when the data is sent from the
other end of the websocket? Here is also the code for the part where
the binary data is sent over the websocket. Also the @onError methods
are in the classes and never called either.

public void SendMessage() throws IOException
{
    for(int i = 0;i<MESSAGE_SIZE;i++)
        message+='\0';
    for(int i = 0;i<ID_SIZE;i++)
        id+='\0';
    ByteBuffer bbuf = ByteBuffer.allocate(1000);
    bbuf.put(id.getBytes());
    bbuf.position(33);
    bbuf.putInt(33,length);
    bbuf.position(37);
    bbuf.put(message.getBytes());
    for(Session session : sessionList)
        session.getBasicRemote().sendBinary(bbuf);
    System.out.println("sent");
}

Jason Ricles

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message