Readme

You might also like

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

Tn hc phn: Lp trnh ng dng phn tn

S tn ch: l thuyt 30/45 tit + thc hnh 30 tit


Dng cho h: DHCQ + DHLT
Mc tiu phn thc hnh: lp trnh phn tn.
Yu cu mi trng: OS (Windows/Linux) + JDK
Ni dung cc bi thc hnh: mi bi nn chia theo n v 3t
TT Tn bi Mc tiu Ti liu tham kho hay hng dn
1 Hng i tng trong Java n tp java v HDT Ti liu hng dn thc hnh
Core Java quyn I v II.
2 Streams Hiu v Streams, c xut file dng Byte v Character Ti liu hng dn th
Core Java quyn I v II.
3 InetAddress, URL, Socket (TCP) Hiu v InetAddress, URL, Socket. Vit c ng dng c
t gia 2 my Ti liu hng dn thc hnh
4 Socket (UDP), Socket (SSL) Vit c ng dng chat gia 2 my theo UDP v SSL
Ti liu hng dn thc hnh
5 Sending Email Using Socket Dng SMTP Server, vit ng dng gi Email bng giao
thc SMTP Ti liu hng dn thc hnh
6 RMI (UnicastRemoteObject) Hiu c phn tn i tng, ng ti c dch v cu
t Ti liu hng dn thc hnh
7 RMI (Activatable) Xy dng ng dng phn tn theo Activatable Ti liu hng
8 n tp RMI Bi tp p dng
9 WebService Hiu WebService, ng ti c mt s dch v n gin Ti liu hng
10 n tp
Bi tp tun 1
Xy dng lp hc sinh, bit rng mi hc sinh c:
Thnh phn d liu: m s, h tn, im trung bnh
Phng thc: set(), get(), input(), output(), rank() - xp loi cho hc sinh theo dtb.
Vit phng thc main(): to mt i tng hc sinh, nhp thng tin cho hc sinh, xut thng t
h.
Tng t, xy dng cc lp vi cc phng thc cn thit v cc thnh phn d liu nh sau:
Hng in my gm: m hng, tn hng, nh sn xut, gi, thi gian bo hnh, in p, cng su
Hng snh s gm: m hng, tn hng, nh sn xut, gi, loi nguyn liu
Hng thc ph-m gm: m hng, tn hng, nh sn xut, gi, ngy sn xut, ngy ht hn dng
Xy dng lp COORDINATE: ta ca im trong khng gian hai chiu.
Thnh phn d liu: honh x v tung y
Cc phng thc gm:
phng thc thit lp chu-n: x = 0, y = 0
phng thc thit lp 2 i s.
phng thc tnh tng cc thnh phn x v y ca 2 im.
phng thc tm im i xng ca mt im.
phng thc in ta ca mt im.
Ti liu tham kho: Slide java c bn
Bi tp tun 2
Vit chng trnh mycopy s dng nh sau: java mycopy filename1 filename2
Nu filename1 v filename2 l 2 file th chng trnh copy ni dung ca filename1 sang filenam
Nu filename2 l th mc th copy filename1 sang th mc filename2
Nu filename1 c tn l con th cho php to filename2 vi ni dung g t bn phm (ging lnh
2. Vit chng trnh cho php ghi danh sch cc sinh vin (ging bi v d 2) vo file student
h sch cc sinh vin ra mn hnh.
3. Vit chng trnh hin th ni dung ca file vn bn trong i tng TextArea.
Ti liu tham kho: Chng 2 (Lung) + Core java I v II.
Bi tp tun 3
Vit chng trnh ly cc thnh phn tng ng ca a ch URL. V d: cho URL sau
http:// www.en.wikipedia.org/wiki/Distributed_computing#Applications
Kt qu:
Protocol: http
Host: www.en.wikipedia.org
Path: wiki/Distributed computing
Fragement Identifier: Application
Vit chng trnh phn gii a ch IP thnh hostname v ngc li
Vit chng trnh chat gia Client v Server
Ti liu tham kho: Chng 3 (Networking)
Bi tp tun 4
Lm li cc v d theo bi ging
Vit ng dng gi v nhn file gia client v server
Gi s my A c 1 file danh sch nh sau: D:\danhsach.txt
1 3 5 7 4 8 12 16 15
Vit chng trnh trn my B c file danh sch trn v thc hin php ton:
Tnh tng gi tr cc s va c c
Tm cc s chn
Tm cc s l
Tm cc s nguyn t
Tong = 61
Cac so chan = 4 8 12 16
Cac so le = 1 3 5 7 15
Cac so nguyen to = 1 3 5 7
Ti liu tham kho: Chng 3 (Networking)
Bi tp tun 5
Vit ng dng gi Email bng giao thc SMTP
Ti liu tham kho: Chng 3 (Networking)
V d mu:
Steps to install the SMTP server
Firstly, from the Start menu, click Control Panel.
Go to Add or Remove Programs.
From the left pane, click Add/Remove Windows Components.
From the Components list, click Application Server, and then click Details.
From the Sub components of Application Server list, click Internet Information S
ervices (IIS), and then click Details.
From the Sub components of Internet Information Services (IIS) list, select the
SMTP Service check box.
Click OK.
Click Next. You might be prompted for the Windows Server 2003 family CD or the n
etwork install path.
Click Finish.
To configure global SMTP settings
In IIS Manager, expand the local computer, right-click Default SMTP Virtual Serv
er, and click Properties.
Change the default settings on the property pages as needed. For information abo
ut individual settings, click Help.
To configure SMTP virtual server components settings
In IIS Manager, expand the local computer, expand Default SMTP Virtual Server, r
ight-click the component you want to configure, and click Properties.
Change the default settings on the property pages as needed.
V d:
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
public class SMTPDemo {
public static void main(String args[]) throws IOException,
UnknownHostException {
String msgFile = "Huy.txt";
String from = "huynhhoc@hoc.com";
String to = "vanbao@hoc.com";
String mailHost = "192.168.1.120";
SMTP mail = new SMTP(mailHost);
if (mail != null) {
if (mail.send(new FileReader(msgFile), from, to)) {
System.out.println("Mail sent.");
} else {
System.out.println("Connect to SMTP server failed!");
}
}
System.out.println("Done.");
}
static class SMTP {
private final static int SMTP_PORT = 25;
InetAddress mailHost;
InetAddress localhost;
BufferedReader in;
PrintWriter out;
public SMTP(String host) throws UnknownHostException {
mailHost = InetAddress.getByName(host);
localhost = InetAddress.getLocalHost();
System.out.println("mailhost = " + mailHost);
System.out.println("localhost= " + localhost);
System.out.println("SMTP constructor done\n");
}
public boolean send(FileReader msgFileReader, String from, String to)
throws IOException {
Socket smtpPipe;
InputStream inn;
OutputStream outt;
BufferedReader msg;

msg = new BufferedReader(msgFileReader);
smtpPipe = new Socket(mailHost, SMTP_PORT);
if (smtpPipe == null) {
return false;
}
inn = smtpPipe.getInputStream();
outt = smtpPipe.getOutputStream();
in = new BufferedReader(new InputStreamReader(inn));
out = new PrintWriter(new OutputStreamWriter(outt), true);
if (inn == null outt == null) {
System.out.println("Failed to open streams to socket.");
return false;
}
String initialID = in.readLine();
System.out.println(initialID);
System.out.println("HELO " + localhost.getHostName());
out.println("HELO " + localhost.getHostName());
String welcome = in.readLine();
System.out.println(welcome);
System.out.println("MAIL From:<" + from + ">");
out.println("MAIL From:<" + from + ">");
String senderOK = in.readLine();
System.out.println(senderOK);
System.out.println("RCPT TO:<" + to + ">");
out.println("RCPT TO:<" + to + ">");
String recipientOK = in.readLine();
System.out.println(recipientOK);
System.out.println("DATA");
out.println("DATA");
String line;
while ((line = msg.readLine()) != null) {
out.println(line);
}
System.out.println(".");
out.println(".");
String acceptedOK = in.readLine();
System.out.println(acceptedOK);
System.out.println("QUIT");
out.println("QUIT");
return true;
}
}
}
Xem kt qu:
Bi tp tun 6
Thc hnh theo v d bi ging
Ti liu tham kho: Chng 4
Bi tp tun 7
Thc hnh theo v d bi ging
Ti liu tham kho: Chng 4
Bi tp tun 8
Bi tp p dng 1
Vit chng trnh cho php Server ng ti dch v sau:
Lu tr danh sch sinh vin vo th mc T:\Studten.dat.
Tm kim sinh vin da vo maSV ca sinh vin.
Vit chng trnh Client minh ha s dng dch v Lu tr danh sch sinh vin thc hin lu
h v tm kim sinh vin theo maSV.
Yu cu: Xy dng lp sinhvien gm mt s thuc tnh v phng thc ph hp, trong maSV l
tc tng dn (bt u t 0).
Bi tp p dng 2
Gi s ta cn thc hin tnh ton gi tr ca biu thc sau:
F (n) = F1(n) + F2 (n)
Trong :
Server1 ng ti dch v tnh ton F1(n) v Server2 ng ti dch v tnh ton F2(n).
Gi s F1 (n) = 1 + 2 + + n v F2 (n) = n!, anh/ch hy ci t Server1 v Server2 ng ti
Client minh ha tnh ton gi tr F(n).
Ti liu tham kho: Chng 4
Bi tp tun 9
Thc hnh theo bi ging
Ti liu tham kho: Chng 4
Bi tp tun 10

You might also like