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


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

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

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail
From Knute Johnson <nospam@knutejohnson.com>
Newsgroups comp.lang.java.programmer
Subject Re: How to receive and send websocket messages in Java?
Date Wed, 07 Mar 2012 14:24:18 -0800
Organization A noiseless patient Spider
Lines 31
Message-ID <jj8n6j$c0e$1@dont-email.me> (permalink)
References <31969353.4397.1331150560621.JavaMail.geo-discussion-forums@vbtv42> <24681763.594.1331155027592.JavaMail.geo-discussion-forums@pbcsl10> <4309843.3.1331158120887.JavaMail.geo-discussion-forums@vblo18>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 8bit
Injection-Date Wed, 7 Mar 2012 22:24:19 +0000 (UTC)
Injection-Info mx04.eternal-september.org; posting-host="mz/LDSJwiWnk3Jnnqg7x+Q"; logging-data="12302"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19+iPJMnE0ZeDDudHmqvsfu"
User-Agent Mozilla/5.0 (Windows NT 5.1; rv:10.0.2) Gecko/20120216 Thunderbird/10.0.2
In-Reply-To <4309843.3.1331158120887.JavaMail.geo-discussion-forums@vblo18>
Cancel-Lock sha1:nwfzR9iu2bfG1kSbqAsCvHQKHMQ=
Xref csiph.com comp.lang.java.programmer:12753

Show key headers only | View raw


On 3/7/2012 2:08 PM, Mihael wrote:
> Thanks for your answer! But i can't understand, how to decode БУЭѓчЮ’ ЫттПДсюƒТкљ№Тмл Е  ?
>
> When I send "1" i get string ББђ,¶3Э
> or send "ping" i get string БДЧ≤’4зџїS
> or send "hello world!" i get string БМяЩрЈfхЬ∞#оЯ≠oэ—
>
> this is special encoded websocket strings? or what?
>
> pseudo code is
>
> InputStream is = s.getInputStream();
> byte buf[] = new byte[64*1024];
> int r = is.read(buf);
> String data = new String(buf, 0, r);
> System.out.println("Recieved Data: " + data);

If you are going to send Strings, you don't want to read and write bytes.

BufferedReader br = new BufferedReader(new InputStreamReader(
  s.getInputStream(),***YOUR CHAR SET GOES HERE***));

br.readLine();

If the server you are connecting to is using a different character set 
you need to use a different constructor for InputStreamReader that sets 
the character set.  See the docs for InputStreamReader.

-- 

Knute Johnson

Back to comp.lang.java.programmer | Previous | NextPrevious 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