With UTF-8 characters are encoded in a variable number of bytes according to various ranges, as you can see here in section "Description": http://en.wikipedia.org/wiki/UTF-8 Since you're sending your bytes as chars but read back as bytes, your last two bytes create chars that later produce two bytes each, and thus you see seven bytes at the other end. You may want to get an output stream from the socket and write single bytes directly.
On Wednesday, August 28, 2013 7:13:31 PM UTC-7, Yoshinori Kohyama wrote: > Hello all. > > Please help me to read and write bytes via Socket. > > For example, assumed that I want to send 5 bytes [0x00, 0x01, 0x7f, 0x80, > 0xff] to a TCP server. > > I did: > (require '[clojure.java.io :refer :all]) > (with-open [s (java.net.Socket. "*ip.of.test.server*" *port_of_test_server > *)] > (let [^java.io.BufferedWriter wtr (writer s) > ^chars obuf (char-array (map char [0 1 127 128 255]))] > (.write wtr obuf 0 5) > (.flush wtr)))) > > Then, my test server received bytes: [0x00, 0x01, 0x7f, 0xc2, 0x80, 0xc3, > 0xbf]. > > * I think I should use a char array so that read() requires 'char[]'. > * What is the valid char value to send a byte 0x80? > * How can I make the char value from 0x80 int? > * How are things about read. > * Does character encoding environment affect? (I use > -Dfile.encoding=UTF-8) > > Thank you in advance. > > Yoshinori Kohyama > -- -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.