Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 27

FILE TRANSFER

TCP SOCKET
WITH JAVA

By:
-- Ayip
Nugraha
-- Dedi

Rumusa
n
Masalah

a. Bagaimana PC1 (server)


dan PC2 (client)
dapat
terhubung?
b. Bagaimana file bisa dikirim
dari PC1 (server) ke PC2
(client)?

Serv
Membuat
socket
er
2

Flowchart

Menyiapkan file yg
akan dikirimkan

Clien
Membuat socket
t

Accept

Connect

Mengirim file

Menerima file

Read

Tutup socket

Tutup socket

Progra
m
Server

public class Server {


public final static int SOCKET_PORT =
13267; // Inisialisasi socket port
public final static String FILE_TO_SEND =
"C:/Users/Riki Yunus/Downloads/Music/Mahou
No Hito - Hanako Oku.mp3; //penentuan
directory file yang akan dikirim

Progra
m
Server

public static void main (String [] args )


throws IOException {
FileInputStream fis = null;
BufferedInputStream bis = null;
OutputStream os = null;
ServerSocket servsock = null;
Socket sock = null;

Progra
m
Server

try {
servsock = new
ServerSocket(SOCKET_PORT);
while (true) {
System.out.println("Menunggu...);
try {
sock = servsock.accept();
System.out.println("Menerima koneksi : "
+ sock);

Progra
m
Server

File myFile = new File (FILE_TO_SEND);


byte [] mybytearray = new byte
[(int)myFile.length()];
fis = new FileInputStream(myFile);
bis = new BufferedInputStream(fis);
bis.read(mybytearray,0,mybytearray.length);
os = sock.getOutputStream();
System.out.println("Sending " +
FILE_TO_SEND + "(" + mybytearray.length + "
bytes)");
os.write(mybytearray,0,mybytearray.length);
os.flush();
System.out.println("Selesai!);

Progra
m
Client

public class Client {


public final static int SOCKET_PORT =
13267;
public final static String SERVER =
"127.0.0.1"; // localhost
public final static String
FILE_TO_RECEIVED = "C:/Users/Riki
Yunus/Downloads/UDP Client-Server/Mahou
No Hito - Hanako Oku.mp3";

WANT BIG IMPACT?

USE BIG
IMAGE.

USE CHARTS
White

Gray

Black

AND TABLES
A

Yellow

10

20

Blue

30

15

10

24

16

Orange

our
office

MAPS

89,526,1
Whoa!
Thats a
24
big number,

89,526,124$
Thats a lot of
185,244
users
money
And a lot of
100%
users
Total success!

OUR PROCESS
IS EASY
first

second

last

LETS REVIEW
SOME
CONCEPTS
Yellow
Is the color of gold, butter
and ripe lemons. In the
spectrum of visible light,
yellow is found between
green and orange.

Blue
Is the colour of the clear
sky and the deep sea. It is
located between violet
and green on the optical
spectrum.

Red
Is the color of blood, and
because of this it has
historically been
associated with sacrifice,
danger and courage.

You can copy&paste graphs from Google Sheets

ANDROID
PROJECT
Show and explain your web, app or
software projects using these
gadget templates.

Place your screenshot


here

iPHONE
PROJECT

Show and explain your web, app or


software projects using these
gadget templates.

Place your screenshot


here

TABLET
PROJECT

Show and explain your web, app or


software projects using these
gadget templates.

Place your screenshot here

DESKTOP
PROJECT
Show and explain your web, app or
software projects using these
gadget templates.

Place your screenshot here

THANKS
!
Any questions?

You can find

CREDITS
Special thanks to all the people who made and released
these awesome resources for free:
Presentation template by SlidesCarnival
Photographs by Unsplash

Presentation design
This presentation uses the following typographies:
Titles: Montserrat
Body copy: Didact Gothic
You can download the fonts on this page:
https://www.google.com/fonts#UsePlace:use/Collection:Montserrat:400,700|Didact+Gothi
c

Click on the arrow button that appears on the top right

You dont need to keep this slide in your presentation. Its only here to serve you as a
design guide if you need to create new slides or download the fonts to edit the presentation
in PowerPoint

SlidesCarnival icons are editable


shapes.
This means that you can:

Resize them without losing


quality.

Change line color, width and


style.
Isnt that nice? :)
Examples:

You might also like