java - Socket Programming Error while Posting XML to Server -
this question has answer here:
public static string posttoserver(string ip_port ,int nodexml) { logger.error("node xml "+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 "+ip_p); ip_ip=integer.parseint(ip_port_split[1]); logger.error("ip_ip "+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 "+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 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 getting posted "+msg); out.flush(); } catch(ioexception ioexception){ logger.error("io exception in sendmessage method "+ioexception); } }
i getting following exception :
io exception 1 java.net.socketexception: software caused connection abort: recv failed
the issue solved. listener not accepting new line(/n) getting posted incorrectly via given code.
Comments
Post a Comment