Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #12749

Re: How to receive and send websocket messages in Java?

From Lew <lewbloch@gmail.com>
Newsgroups comp.lang.java.programmer
Subject Re: How to receive and send websocket messages in Java?
Date 2012-03-07 13:17 -0800
Organization http://groups.google.com
Message-ID <24681763.594.1331155027592.JavaMail.geo-discussion-forums@pbcsl10> (permalink)
References <31969353.4397.1331150560621.JavaMail.geo-discussion-forums@vbtv42>

Show all headers | View raw


On Wednesday, March 7, 2012 12:02:40 PM UTC-8, Mihael wrote:
> Hello!
> 
> I try to create websocket server on Java
> 
> this is my draft of code http://pastebin.com/k1D46cV7
> 
> i try to connect from Chrome on Mac version 17.0.963.66
> from this test page http://websocket.org/echo.html
> 
> And connection success
> 
> But when i send any data to server, in console on server application i see string like 
> 
> БУЭѓчЮ’ ЫттПДсюƒТкљ№Тмл Е

That's because you aren't controlling the string encoding.

> how can i [sic] decode this string to normal?

What is "normal"?

> And when i try to send answer from server - client not get message...
> 
> Please, give me code for right receive and decode message and right encode and send message.

What is the native platform encoding on the server side?

Always include encoding explicitly in the calls to encode/decode strings.

Don't manipulate bytes to make Strings. Even 'char' isn't safe, as code points can be wider than 16 bits.

Don't hard-code numeric values for end-of-line.

Use a 'Reader' and 'Writer' instead of raw streams.

Spell "receive" correctly.

-- 
Lew

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

How to receive and send websocket messages in Java? Mihael <isaev.mihael@gmail.com> - 2012-03-07 12:02 -0800
  Re: How to receive and send websocket messages in Java? Mihael <isaev.mihael@gmail.com> - 2012-03-07 12:03 -0800
  Re: How to receive and send websocket messages in Java? Lew <lewbloch@gmail.com> - 2012-03-07 13:17 -0800
    Re: How to receive and send websocket messages in Java? Mihael <isaev.mihael@gmail.com> - 2012-03-07 14:08 -0800
      Re: How to receive and send websocket messages in Java? Knute Johnson <nospam@knutejohnson.com> - 2012-03-07 14:24 -0800

csiph-web