Yup that flip did it and it works. Yes haha that was one of the many
reasons I didn't major in something with more writing. Luckily its
just a test method thats why I didn't double check the spelling.
Thanks for the help.

On Tue, Nov 18, 2014 at 3:00 PM, Konstantin Kolinko
<knst.koli...@gmail.com> wrote:
> 2014-11-18 22:14 GMT+03:00 Jason Ricles <jgr...@alum.lehigh.edu>:
>> 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());
>
> 1. I think that you are missing bbuf.flip()  here.
>
>>     for(Session session : sessionList)
>>         session.getBasicRemote().sendBinary(bbuf);
>>     System.out.println("sent");
>> }
>>
>
> 2. There are tests for receiving binary messages in Tomcat,  e.g.
> test/org.apache.tomcat.websocket.TesterEchoServer  class.
>
> 3. BTW, there is a typo in method name.  s/recieved/received/
>
> Best regards,
> Konstantin Kolinko
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> For additional commands, e-mail: users-h...@tomcat.apache.org
>

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

Reply via email to