Results 1 to 3 of 3
  1. #1
    Chrillz is offline Member
    Join Date
    Jul 2011
    Rep Power

    Default TCP/IP client not working properly

    Hi! I have written code for a TCP/ip client that is supposed to connect to a server and receive some data. This works successfully when I connect to a TCP server in Java, but when I try to connect to a TCP server that consists of an embedded system I get the following message:

    " invalid stream header: 30313233"

    30 31 32 33 is the hexadecimal representation of the data that the server sends to connecting clients, so something is working, but why do I get this Exception?

    the code for the client is here:
    Java Code:
    public class TCPClientD {
        private String serverIP;
        private int serverPort;
        String fail;
        public TCPClientD(String serverIP, int serverPort) {
            this.serverIP = serverIP;
            this.serverPort = serverPort;
            Thread thread = new Thread(new ConnectAndListenToServer());
        private class ConnectAndListenToServer implements Runnable {
            public void run() {
                try {
                    Socket socket = new Socket(
                    ObjectInputStream input = new ObjectInputStream(
                    String message;
                    while (true) {
                        message = input.readUTF();
                } catch (IOException e) {
                    fail = e.getMessage();
        public static void main(String[] args) {
            new TCPClientD("", 5555);
    Thankful for answers! / Christian

  2. #2
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Tucson, AZ
    Rep Power


    This is sort of a guess, but I may have run into the opposite problem recently. I was screwing around with my own InputStream extension (connected to a Java server) and I was getting some gibberish before my data. I soon discovered that the gibberish was actually the Byte Order Mark.

    Perhaps your InputStream is expecting a BOM before the data, and throwing an exception because it's not seeing one.
    Last edited by kjkrum; 07-20-2011 at 02:53 AM.
    Get in the habit of using standard Java naming conventions!

  3. #3
    Chrillz is offline Member
    Join Date
    Jul 2011
    Rep Power


    I googled the message and found a thread describing the same problem, turns out the solution is to use the DataInputStream instead of ObjectInputStream.. Thanks for the reply!

Similar Threads

  1. Why this block is not working properly?
    By juhiswt in forum New To Java
    Replies: 2
    Last Post: 03-13-2011, 12:08 PM
  2. date is not working properly
    By newnewgen in forum New To Java
    Replies: 1
    Last Post: 10-12-2010, 10:04 AM
  3. event handler not working properly
    By H3rtaherta in forum Java 2D
    Replies: 3
    Last Post: 11-24-2008, 03:39 AM
  4. My code is not working properly ..modify it
    By Shyam Singh in forum New To Java
    Replies: 14
    Last Post: 07-16-2008, 06:48 PM
  5. Log4j not working properly....
    By prakash_dev in forum Advanced Java
    Replies: 0
    Last Post: 03-17-2008, 01:13 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