Results 1 to 4 of 4
  1. #1
    roi
    roi is offline Member
    Join Date
    Nov 2016
    Posts
    2
    Rep Power
    0

    Default Client in Java Server in another platform

    Hi,
    I'm very new to JAVA,
    I'm trying to build a client which will send to a server numbers (double),
    the server receiving strange charters(like Japanese words), what should I change in the code in order to see it right in the server?


    Java Code:
         BufferedReader in = null;
               OutputStream out = null;
               Socket sock = null;
        
               try {
                   sock = new Socket("127.0.0.1",9422 );
                   out = sock.getOutputStream();
                   in = new BufferedReader(new InputStreamReader(sock.getInputStream()));
        
                       String line = String.valueOf(tick.getBid()); 
                       String responseline = null;
    
        
       while (true) {
      
           out.write(line.getBytes("ISO-8859-1"));
       
       out.flush();
       System.out.println("data sent " );
       System.out.println("val returned"+in.readLine());
                   }
               }
               catch (IOException ioe) {
                   System.err.println(ioe);
               }
               finally {
                  
               }

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,423
    Blog Entries
    7
    Rep Power
    27

    Default Re: Client in Java Server in another platform

    Make that InputStreamReader UTF-8 encoding (it has a constructor for that purpose). Also write UTF-8 encoded bytes for your OutputStream, not ISO-8859-1 encoded.

    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

  3. #3
    roi
    roi is offline Member
    Join Date
    Nov 2016
    Posts
    2
    Rep Power
    0

    Default Re: Client in Java Server in another platform

    Quote Originally Posted by JosAH View Post
    Make that InputStreamReader UTF-8 encoding (it has a constructor for that purpose). Also write UTF-8 encoded bytes for your OutputStream, not ISO-8859-1 encoded.

    kind regards,

    Jos
    Thanks for your answer,
    I tried to do that:
    Java Code:
      try {
                    
                   Socket  sock = new Socket("127.0.0.1",9422 );
                   BufferedWriter wr=new BufferedWriter(new OutputStreamWriter(sock.getOutputStream(),"UTF-8"));
                   String line = String.valueOf(tick.getBid());
                   wr.write("1.1");     
                       wr.flush();
               }

    but it still not works,
    the server receive the attached photo.


    Any ideas please?

    thanks
    Attached Thumbnails Attached Thumbnails Client in Java Server in another platform-capture.png  
    Last edited by roi; 11-30-2016 at 07:51 AM.

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,423
    Blog Entries
    7
    Rep Power
    27

    Default Re: Client in Java Server in another platform

    Did you also change the reader?

    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

Similar Threads

  1. Replies: 10
    Last Post: 05-17-2014, 07:50 PM
  2. Replies: 2
    Last Post: 09-24-2010, 11:31 AM
  3. Introduction To RCP(Rich Client Platform)
    By JavaForums in forum Eclipse
    Replies: 0
    Last Post: 05-24-2007, 03:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •