below have put fragment of code understand problem. have server code, works fine first time client loads , sends packet. after first packet received, server stuck on "accept".
i have wireshark configured port, , server getting packets. wonder why accept wont return more once. driving me nuts.
server code
public class dapool implements runnable { private serversocket serversocket; private arraylist<da> pool; private linkedlist<socket> clientconnq; public dapool(int newpoolsize, int serverport) { try { serversocket = new serversocket(serverport, 500, inetaddress.getbyname("127.0.0.1")); } catch (ioexception e) { e.printstacktrace(); return; } poolsize = newpoolsize; clientconnq = new linkedlist<socket>(); pool = new arraylist<da>(poolsize); da devicethread; (int threads = 0; threads < poolsize; threads++) { devicethread = new da(); connpool.add(devicethread); devicethread.start(); } } public void run() { while (true) { socket incomingsocket; try { incomingsocket = serversocket.accept(); } catch (ioexception e) { e.printstacktrace(); return; } insertnewconntoq(incomingsocket); } } private class da extends thread { private socket clientsocket; private objectinputstream inputobjectstream; public da() { } public void run() { while (true) { while (clientconnq.isempty()) { synchronized (clientconnq) { try { clientconnq.wait(); } catch (interruptedexception ignored) { ignored.printstacktrace(); } } } synchronized (clientconnq) { clientsocket = (socket) clientconnq.removefirst(); try { inputobjectstream = new objectinputstream(clientsocket.getinputstream()); } catch (ioexception e) { e.printstacktrace(); return; } // useful here } } } } }
client code
public class sendqueue extends thread { linkedlist<message> requestq; message sendrequest, requestmessage; socket clientsocket; outputstream outputstream; objectoutputstream objectoutputstream; public sendqueue(socket newclientsocket) { requestq = new linkedlist<message>(); clientsocket = newclientsocket; } public void run() { while (true) { synchronized (requestq) { while (requestq.isempty()) { try { requestq.wait(); } catch (interruptedexception ignored) { ignored.printstacktrace(); } } sendrequest = requestq.removefirst(); } try { outputstream = clientsocket.getoutputstream(); objectoutputstream = new objectoutputstream(outputstream); objectoutputstream.writeobject(sendrequest); objectoutputstream.flush(); outputstream.flush(); } catch (ioexception e) { e.printstacktrace(); } catch (runtimeexception e) { e.printstacktrace(); } } } public int sendrequest(message message) { synchronized (requestq) { requestq.addlast(message); requestq.notify(); } return 0; } }
i don't see timeout being set on serversocket.
serversocket.accept()
blocking operation block until either error occurs, timeout occurs, or connection accepted.
try
serersocket.setsotimeout(10000)
you don't seem closing streams when finished.
Comments
Post a Comment