@Test
public void sendFileServerToClient() throws Exception {
File fDir = testFolder.newFolder();
String content = TestUtils.randomUnicodeString(10000);
File file = setupFile(fDir.toString(), "some-file.txt", content);
Buffer expected = Buffer.buffer(content);
Buffer received = Buffer.buffer();
server.connectHandler(sock -> {
sock.handler(buf -> {
sock.sendFile(file.getAbsolutePath());
});
});
server.listen(ar -> {
assertTrue(ar.succeeded());
client.connect(1234, "localhost", ar2 -> {
assertTrue(ar2.succeeded());
NetSocket sock = ar2.result();
sock.handler(buff -> {
received.appendBuffer(buff);
if (received.length() == expected.length()) {
assertEquals(expected, received);
testComplete();
}
});
sock.write("foo");