How can I simulate a socket disconnection?
My application uploads files to server of my client, but he want special "pause upload" function. I cant simply close connection, not even kill process - he need to lost connection otherwise his server application delete unfinished file - so i have to simulate in code "cable unplug" - do you have any suggestion? thanks for开发者_如何学C your help and sorry for my english :) jirka
You can use Mockito to create a Socket
mock for your unit tests, as suggested on this question: Testing Java Sockets
If you wrote both the client and the server, maybe the better option is to send some OOB data to tell the server that you are pausing (or a message to tell the server to not delete the file on next socket close). It is usually better to be explicit instead of relying on side effects of certain actions - in your case, closing a socket without explicit connection termination.
精彩评论