Return-Path: X-Original-To: apmail-tomcat-users-archive@www.apache.org Delivered-To: apmail-tomcat-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 3425310761 for ; Tue, 18 Nov 2014 20:29:16 +0000 (UTC) Received: (qmail 59641 invoked by uid 500); 18 Nov 2014 20:29:12 -0000 Delivered-To: apmail-tomcat-users-archive@tomcat.apache.org Received: (qmail 59569 invoked by uid 500); 18 Nov 2014 20:29:12 -0000 Mailing-List: contact users-help@tomcat.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Tomcat Users List" Delivered-To: mailing list users@tomcat.apache.org Received: (qmail 59558 invoked by uid 99); 18 Nov 2014 20:29:12 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 18 Nov 2014 20:29:12 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (nike.apache.org: local policy) Received: from [209.85.160.177] (HELO mail-yk0-f177.google.com) (209.85.160.177) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 18 Nov 2014 20:28:46 +0000 Received: by mail-yk0-f177.google.com with SMTP id 9so5438128ykp.36 for ; Tue, 18 Nov 2014 12:28:45 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type; bh=rqqvmhvSCMxBjF+GtKnivJXqEvLFI7ZLfESzM8SUuv4=; b=Em/+EnSLIr7LZq8jDB2wNBpTrIvUomjogq4w6yRQF1WcRRVVke3l8FNFtI8mvxCpwZ RqDzQ/k2VVrRHyJHR91WUAh/aDjdAqJtnsgh+ije6iCRzf2JRyLZ5Sird11rKm1XrXQ4 hRutjTRP2kpe55EziBmiDoso9dRsSNVdYoZ8G0yVQpWqkqfEoYV8GA7G4INv0NG2u74E D+rs5HPzqnAEjiRBfI44rRKdcBXOU1m1B4SGlADtEQN+wRoHEHowUS5B+1kR0bS56fDB 4oCeqhTuhCaQMu5kkctDbFZwkSe2m+NBpzVPJOFuvRx5plZK2SBCjvNgvY/6SpCj8m5D kt9Q== X-Gm-Message-State: ALoCoQnw9aEs96UnJZ1OP9FPxbiLy4RnB/Gcd8jnWUxFyeP+PBzOb6YRAgkD6yvmfhEC6DK3uDcI MIME-Version: 1.0 X-Received: by 10.236.16.230 with SMTP id h66mr5694842yhh.145.1416342525397; Tue, 18 Nov 2014 12:28:45 -0800 (PST) Received: by 10.170.204.82 with HTTP; Tue, 18 Nov 2014 12:28:45 -0800 (PST) In-Reply-To: References: Date: Tue, 18 Nov 2014 15:28:45 -0500 Message-ID: Subject: Re: Websocket @OnMessage is never firing for binary messages only text From: Jason Ricles To: Tomcat Users List Content-Type: text/plain; charset=UTF-8 X-Virus-Checked: Checked by ClamAV on apache.org Why is the bytebuffer now filled with 0 and no data after doing a flip? On Tue, Nov 18, 2014 at 3:12 PM, Jason Ricles wrote: > 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 > wrote: >> 2014-11-18 22:14 GMT+03:00 Jason Ricles : >>> 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+='\0'; >>> for(int i = 0;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-unsubscribe@tomcat.apache.org >> For additional commands, e-mail: users-help@tomcat.apache.org >> --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org For additional commands, e-mail: users-help@tomcat.apache.org