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);
    }
}

我得到以下异常:

Io 异常 1 java.net.SocketException:软件导致连接中止:recv 失败

4

1 回答 1

0

问题解决了。侦听器不接受通过给定代码错误发布的新行 (/n)。

于 2017-01-16T03:21:19.770 回答