Jisan Mahmud
Jisan Mahmud

Reputation: 201

JAVA : Transferring files through socket

What I'm doing : I am writing a program on client-server file transfer through socket connection. The server sends files to client computer through buffered ObjectOutputStream. The file is being sent by sending it byte by byte

What I want to do : To be able to send pause/cancel signal from both end.

The problem : As the file is being sent byte by byte, I'm confused how to send a pause/cancel signal from server to client. Help please.

Additional Info : If I send an integer/a byte from the server to the client to indicate that the transfer should be paused or cancelled, it should be confusing the client computer may read these bytes as part of the file!

Upvotes: 1

Views: 653

Answers (1)

Peter Lawrey
Peter Lawrey

Reputation: 533880

I wouldn't use an ObjectOutptuStream as this can be inefficient. Sending one Byte at a time is very inefficient.

I would use a DataOutputStream instead.

In any case the solution is much the same. The sender can pause by not sending data. The receiver can pause by not reading data which will cause the sender to block.

Upvotes: 2

Related Questions