Java application to communicate with PIC32 through RN171 wireless module

Discussion in 'Programmer's Corner' started by Rphil, Mar 31, 2014.

  1. Rphil

    Thread Starter New Member

    Oct 6, 2012
    10
    0
    Hi everybody. I'm writing a Java code which have to send and receive some data from an elecronic system through wireless. The connection is done with the RN-171. I'm now trying to connect to the RN-171 network and to send and receive some data. Although I can in my java code set up an ObjectOutputStream and send some data to the RN-171 properly, I can't set up an ObjectInputStream and my app launches the following exception:
    Code ( (Unknown Language)):
    1.  
    2. java.io.StreamCorruptedException: invalid stream header: 2A48454C
    3.  at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:804)
    4.  at java.io.ObjectInputStream.<init>(ObjectInputStream.java:299)
    5.  at TestController.sendParametersToWirelessModule(TestController.java:44)
    6.  at TestController.main(TestController.java:30)
    7.  
    The code which generates the exception is:
    Code ( (Unknown Language)):
    1.  
    2.  try{
    3.  //1. creating a socket to connect to the server
    4.  requestSocket = new Socket("1.2.3.4", 2000);
    5.  System.out.println("Connected to localhost in port 2004");
    6.  //2. get Input and Output streams
    7.  out = new ObjectOutputStream(requestSocket.getOutputStream());
    8.  out.flush();
    9.  --> in = new ObjectInputStream(requestSocket.getInputStream());
    10.  //3: Communicating with the server
    11.  sendMessage(message);          }
    12.  
    (The arrow indicates the code line which generates exception)

    I cannot find a solution to this problem, could anyone help me please?
    Thank you in advance.

    Regards
    Filippo
     
Loading...