0
public static String postTOServer(String ip_port ,int nodexml)
{
    logger.error("node Xml is "+Node.writeToString(nodexml,true));
    Socket requestSocket = null;
    ObjectOutputStream out = null;
    ObjectInputStream in = null;
    String message = null;
    String ip_port_split[] = ip_port.split("@");
    String ip_p = null; 
    Integer ip_ip = 0;
    if(ip_port_split.length != 0 && nodexml != 0)
    {
        ip_p=ip_port_split[0];
        logger.error("Ip_p is "+ip_p);
        ip_ip=Integer.parseInt(ip_port_split[1]);

        logger.error("Ip_ip is "+ip_ip);
        try{

        requestSocket = new Socket(ip_p, ip_ip);
        out = new ObjectOutputStream(requestSocket.getOutputStream());
        out.flush();
        in = new ObjectInputStream(requestSocket.getInputStream());
                  logger.error("request Socket Input Stream "+requestSocket.getInputStream());

                /*FileInputStream fstream = new FileInputStream(filepath);

                  BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
                  String strLine;
                  String xml = "";
                  while ((strLine = br.readLine()) != null)   {
                      xml = xml + strLine;
                  }*/
                sendMessage(Node.writeToString(nodexml, false),out);
                in.
                message = (String)in.readObject();
                logger.error("The Message is "+message);

    }
    catch(ClassNotFoundException classNot){
        logger.error("Class Not Found "+classNot);
    } 
    catch(UnknownHostException unknownHost){
        logger.error("Unknown Host Exception "+unknownHost);
    }
    catch(IOException ioException){
        logger.error("Io Exception 1 "+ioException);
    }
    finally{
        //4: Closing connection
            try{
                in.close();
                out.close();
                requestSocket.close();
            }
            catch(IOException ioException){
                logger.error("Io Exception in Finally Block "+ioException);
            }
        }
    }
    else{
        throw new BsfConstraintViolationException("Error Message");

        }
    return message;
}
public static void sendMessage(String msg,ObjectOutputStream out)
{
    try{
        out.writeObject("Content-Type: text/xml; charset=\"utf-8\"\r\n");
        //out.writeObject(msg);

        logger.error("The Message Which is getting Posted "+msg);
        out.flush();
    }
    catch(IOException ioException){
        logger.error("Io Exception in sendMessage MEthod "+ioException);
    }
}

I am getting following Exception :

Io Exception 1 java.net.SocketException: Software caused connection abort: recv failed

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
Rohit Narvekar
  • 349
  • 3
  • 9

1 Answers1

0

The issue is solved. The listener was not accepting the new line(/n) which is getting posted incorrectly via given code.

Rohit Narvekar
  • 349
  • 3
  • 9
  • A line-feed is `\n`, not `/n`, but your code uses `writeObject()`, not a line termination protocol. Unclear how this answers the question. – user207421 Jan 16 '17 at 03:26