Results 1 to 3 of 3
  1. #1
    Gatsu is offline Member
    Join Date
    Dec 2012
    Posts
    42
    Rep Power
    0

    Default socketserver datainputstream readUTF

    nevermind sorry u can lock this thread :P I solved it and what I typed was not the problem so pfft thanks anyway
    Last edited by Gatsu; 08-06-2013 at 07:57 PM.

  2. #2
    sankubha is offline Member
    Join Date
    Aug 2013
    Posts
    1
    Rep Power
    0

    Default Re: socketserver datainputstream readUTF

    in server u r sending int type data ... but in client u r receiving it as string ..... just change the server side also to readUTF

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,361
    Blog Entries
    7
    Rep Power
    20

    Default Re: socketserver datainputstream readUTF

    This was the original text in the OP:

    Hi i have a server and a client who wants to communicate in different ways and depending on whats in writeUTF() on the sending part.

    My server does like this to send a message to the client:

    Java Code:
    public void writeText(DataOutputStream inDos, String inText) throws IOException
     {
     String str = inText;
    
     inDos.writeUTF("MESSAGE");
    
     byte[] data = str.getBytes("UTF-8");
     inDos.writeInt(data.length);
     inDos.write(data);
    
     //inDos.writeBytes(inText);
    
     inDos.flush();
     }
    and then my client recieves it like this:

    mDis = new DataInputStream(new BufferedInputStream(mClientSocket.getInputStream() ));

    Java Code:
    while(true)
     {
     // check for incoming message
     if(mDis.readUTF().equals("MESSAGE"))
     {
     readText(mDis);
     }
     }
    after that readText() method converts bytes to string buuut my problem is at the readUTF(), I get the error:

    java.io.UTFDataFormatException: malformed input around byte 0
    thread closed

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Error in DataInputStream
    By sanshik in forum JCreator
    Replies: 8
    Last Post: 07-10-2011, 02:37 PM
  2. DataInputStream
    By robs in forum Java Gaming
    Replies: 7
    Last Post: 04-14-2011, 06:27 PM
  3. SocketServer 24/7
    By machro in forum Java Servlet
    Replies: 0
    Last Post: 04-04-2011, 02:22 PM
  4. DataInputStream readLine()
    By ravian in forum New To Java
    Replies: 2
    Last Post: 11-26-2007, 10:44 PM
  5. Replies: 1
    Last Post: 08-07-2007, 07:16 AM

Posting Permissions

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