Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 将XML发布到服务器时发生套接字编程错误_Java_Sockets - Fatal编程技术网

Java 将XML发布到服务器时发生套接字编程错误

Java 将XML发布到服务器时发生套接字编程错误,java,sockets,Java,Sockets,我得到以下例外情况: Io异常1 java.net.SocketException:软件导致的连接中止:recv失败问题已解决。侦听器未接受新行(/n),该行通过给定代码错误发布。更详细一点会有所帮助。例如,您从何处获得该错误?服务器是否可能过早关闭连接?换行是\n,而不是/n,但您的代码使用writeObject(),而不是线路终止协议。不清楚这是如何回答这个问题的。 public static String postTOServer(String ip_port ,int nodexml)

我得到以下例外情况:


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

问题已解决。侦听器未接受新行(/n),该行通过给定代码错误发布。

更详细一点会有所帮助。例如,您从何处获得该错误?服务器是否可能过早关闭连接?换行是
\n
,而不是
/n
,但您的代码使用
writeObject()
,而不是线路终止协议。不清楚这是如何回答这个问题的。
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);
    }
}