10 laboratoriya Prtokol asosida ma’lumot almashish klient-server dasturini yaratish Klient-server dasturini ishlab chiqishda NetBeans ide muxiti va java dasturiy ta’minotini o‘rnatish


FTP protokoli asosida tarmoqda fayllarni almashish server dasturini ishlab chiqish va natija olish



Download 1,78 Mb.
bet3/3
Sana28.05.2022
Hajmi1,78 Mb.
#612629
1   2   3
Bog'liq
10 laboratoriya

FTP protokoli asosida tarmoqda fayllarni almashish server dasturini ishlab chiqish va natija olish

FTP protokoli asosida tarmoqda fayllarni almashish server dasturini ishlab chiqish va natija olishda biz server qismini yaratib olishimiz zarur bo‘ladi. Bunnig uchun kuyindagi amallarni bajarishimiz zarur.


package ftpserver;


import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
*


*/
public class FTPServer {
public static void main(String args[]) throws Exception
{ ServerSocket soc=new ServerSocket(5217);
System.out.println("FTP Server Started on Port Number 5217");
while(true)
{ System.out.println("Waiting for Connection ...");
transferfile t=new transferfile(soc.accept());
} }}class transferfile extends Thread
{ Socket ClientSoc;
DataInputStream din;
DataOutputStream dout;
transferfile(Socket soc)
{
try { ClientSoc=soc;
din=new DataInputStream(ClientSoc.getInputStream());
dout=new DataOutputStream(ClientSoc.getOutputStream());
System.out.println("FTP Client Connected ...");
start();
} catch(Exception ex)
{ } } void SendFile() throws Exception
{ String filename=din.readUTF();
File f=new File(filename);
if(!f.exists())
{ dout.writeUTF("File Not Found");
return;
} else
{ dout.writeUTF("READY");
FileInputStream fin=new FileInputStream(f);
int ch;
do { ch=fin.read();
dout.writeUTF(String.valueOf(ch));
} while(ch!=-1);
fin.close();
dout.writeUTF("File Receive Successfully");
} }
void ReceiveFile() throws Exception
{ String filename=din.readUTF();
if(filename.compareTo("File not found")==0)
{ return;
} File f=new File(filename);
String option;
if(f.exists())
{ dout.writeUTF("File Already Exists");
option=din.readUTF();
} else
{ dout.writeUTF("SendFile");
option="Y";
} if(option.compareTo("Y")==0)
{ FileOutputStream fout=new FileOutputStream(f);
int ch;
String temp;
do {
temp=din.readUTF();
ch=Integer.parseInt(temp);
if(ch!=-1)
{ fout.write(ch);
} }while(ch!=-1);
fout.close();
dout.writeUTF("File Send Successfully");
} else
{ return;
} } public void run()
{ while(true)
{ try
{ System.out.println("Waiting for Command ...");
String Command=din.readUTF();
if(Command.compareTo("GET")==0)
{ System.out.println("\tGET Command Received ...");
SendFile();
continue;
} else if(Command.compareTo("SEND")==0)
{
System.out.println("\tSEND Command Receiced ...");
ReceiveFile();
continue;
} else if(Command.compareTo("DISCONNECT")==0)
{ System.out.println("\tDisconnect Command Received ...");
System.exit(1);
} } catch(Exception ex)
{ } } } }
Dasturi ishlab chiqilgandan so‘ng uni ishga tushiramiz. Ushbu oyna yordami aloqa hosil qilinadi. Va natija quyidagicha bo‘ladi.






7-rasm. Dastur oynasi




8-rasm. Dastur oynasi





Ushbu dastur yordamida FTP prtokoli yordamida tarmoqda fayllarni almashish mumkin bo‘ladi.
Download 1,78 Mb.

Do'stlaringiz bilan baham:
1   2   3




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish