java - Socket stream hangs when using IOUtils.copy() -


i want send inputstream containing xml client server. said server manipulates xml stream using streaming api xml (stax) , sends client.

i mange send xml server, client receives answer, doesn't exit because server never finishes reading inputstream form client. when server dumping input system.out instead of sending something, reading finishes...

edit forgot mention ioutils.copy() running in 2 separate threads on client.

here code reproduce this, i've replaced stax part ioutils.copy() on server.

server

serversocket serversocket = new serversocket(port); socket clientsocket = serversocket.accept();  inputstream in = clientsocket.getinputstream(); outputstream out = clientsocket.getoutputstream(); ioutils.copy(in, out); 

client

socket socket = new socket(host, port); fileinputstream fin = new fileinputstream(file); outputstream out = socket.getoutputstream(); ioutils.copy(fin, out)  inputstream in = socket.getinputstream(); ioutils.copy(in, system.out) 

you must flush , close inputstream , outputstream. this:

serversocket serversocket = new serversocket(port); socket clientsocket = serversocket.accept();  inputstream in = clientsocket.getinputstream(); outputstream out = clientsocket.getoutputstream(); ioutils.copy(in, out);  //add  out.flush(); in.close(); out.close; 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -