Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

client->server : data flow prob.

 
Harish Kashyap
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

hi friends!
i have a problem.
i'm creating a client-server aplication. client is an applet and server is an application.
on the client side i send some message to server using writeChars() method of DataOutputStream and reading it on server side using readLine() method. and same vice versa.

now my problem is that the string i'm recieving is same as sent by other end but its size is doubled(i.e. no. of characters)
while printing it on the console it gives the same string.
the only problem is that it inserts a null character between each two characters of the string.
i'm working on linux platform.
please suggest some solution.
thanx
harish
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the J2SE:
writeChar(int): Writes a char to the underlying output stream as a 2-byte value, high byte first.
writeChars(String) simply runs the writeChar(int) method as many times as the length of the String.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Harish Kashyap:

hi friends!
i have a problem.
i'm creating a client-server aplication. client is an applet and server is an application.
on the client side i send some message to server using writeChars() method of DataOutputStream and reading it on server side using readLine() method. and same vice versa.

now my problem is that the string i'm recieving is same as sent by other end but its size is doubled(i.e. no. of characters)
while printing it on the console it gives the same string.
the only problem is that it inserts a null character between each two characters of the string.
i'm working on linux platform.
please suggest some solution.
thanx
harish

The string you are receiving is UNICODE representation..two bytes per character, which would appear to Linux to be (null + ASCII) representation. By using OutputStreamWriter and specifying "latin1" encoding, you can send string as ASCII.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic