3

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

jirka
  • 31
  • 2
  • You have to stop sending data and stop sending confirmations for arriving data (I think this is not possible with Java's socket implementation, since this is done by the OS), and then wait long enough so some timeout at the server side triggers. – Paŭlo Ebermann Sep 13 '11 at 11:27
  • 3
    use firewall settings (iptables or windows firewall) or just pull off the cable, turn off the wireless router, or send RST signal. you can do it easily w/ TCPView on windows. – bestsss Oct 24 '11 at 20:48
  • @PaŭloEbermann, that won't work since the timeout are long enough (like 2 hours) and/or they have KEEP_ALIVE enabled. – bestsss Oct 24 '11 at 20:50
  • @bestsss Clever idea, but it'd be tricky if you want to do automatic tests, mainly on Windows. – PaoloVictor Oct 24 '11 at 23:29
  • @PaoloVictor, using WinPCap to send a RST is not difficult, dunno if there is a library/application to do so. – bestsss Oct 25 '11 at 06:32

2 Answers2

2

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

Community
  • 1
  • 1
PaoloVictor
  • 1,296
  • 8
  • 18
0

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.

vhallac
  • 13,301
  • 3
  • 25
  • 36