java - Close server button problems -
i new java. start server button
jbutton startserverbutton = new jbutton("start"); startserverbutton.addactionlistener(new actionlistener() { public void actionperformed(actionevent e) { if (e.getactioncommand().equals("start")) { runnable serverrunnable = new runnable() { public void run() { runserver(); } }; thread serverthread = new thread(serverrunnable); serverthread.start(); } } });
and want close button
jbutton endserverbutton = new jbutton("end"); endserverbutton.addactionlistener(new actionlistener() { public void actionperformed(actionevent e) { if (e.getactioncommand().equals("end")) { closeconnection(); } } });
but close button doesnt work... please help! here's close function
private void closeconnection() { displaymessage("\nterminating connection\n"); try { output.close(); input.close(); connection.close(); } catch (ioexception ioexception) { ioexception.printstacktrace(); }
try these options:
1) put end operation in new thread , close start thread' io & socket connection. (means closing 1st thread socket connection thread)
2) in end operation thread, set start thread' socket timeout.
regards,
Comments
Post a Comment