jirka
jirka

Reputation: 31

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 your help and sorry for my english :) jirka

Upvotes: 3

Views: 2336

Answers (2)

vhallac
vhallac

Reputation: 13907

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.

Upvotes: 0

PaoloVictor
PaoloVictor

Reputation: 1306

You can use Mockito to create a Socket mock for your unit tests, as suggested on this question: Testing Java Sockets

Upvotes: 2

Related Questions