Java Reference
In-Depth Information
return
return
;
}
iif
(
debug
)
System
.
err
.
println
(
"Got packet of size "
+
inp
.
getLength
());
/* Print the data from the packet */
System
.
out
.
write
(
buffer
,
4
,
inp
.
getLength
()-
4
);
/* Ack the packet. The block number we
* want to ack is already in buffer so
* we just change the opcode. The ACK is
* sent to the port number which the server
* just sent the data from, NOT to port
* TFTP_PORT.
*/
buffer
[
OFFSET_REQUEST
] =
OP_ACK
;
outp
.
setLength
(
4
);
outp
.
setPort
(
inp
.
getPort
());
sock
.
send
(
outp
);
}
while
while
(
inp
.
getLength
() ==
PACKET_SIZE
);
iif
(
debug
)
System
.
err
.
println
(
"** ALL DONE** Leaving loop, last size "
+
inp
.
getLength
());
}
}
To test this client, you need a TFTP server. If you are on a Unix system that you administer,
you can enable the TFTP server to test this client just by editing the file
/etc/inetd.conf
and
restarting or reloading the
inetd
server.
inetd
is a program that listens for a wide range of
connections and starts the servers only when a connection from a client comes along (a kind
etd.conf
, and reloaded
inetd
:
tftp dgram udp wait root /usr/libexec/tftpd tftpd -s /tftpboot
Then I put a few test files, one named
foo
, into the
/tftpboot
directory. Running:
$
java network.RemCat localhost foo