You are on page 1of 21

Mng My Tnh 1

TRNG I HC BCH KHOA TP. H CH MINH Khoa Khoa hc & K thut My tnh

BO CO ASSIGNMENT 2
Mn hc: MNG MY TNH 1

Gio vin hng dn: Nguyn Thanh Ton Nhm thc hin Nhm CSER 50802626 50802669 L Hng Vinh Nguyn Mu Quang V

TP H Ch Minh 12/2010
CSER Group | Bo co Assignment 2 Trang 1

Mng My Tnh 1

MC LC

I. II. III. IV. V.


VI.

Chi tit yu cu Thit k Chi tit ng dng Chi tit phng n v qu trnh hin thc ng dng nh gi kt qu hin thc Cc chc nng m rng
Hng dn s dng

CSER Group | Bo co Assignment 2

Trang 2

Mng My Tnh 1

I.

Chi tit yu cu:

Xy dng ng dng P2P chat theo mt Protocol c cung cp sn, s dng Giao thc TCP/IP, p ng nhng yu cu sau: ng dng cho php hai ngi s dng hai my khc nhau c th chat vi nhau. Mt ngi c th chat vi nhiu ngi khc. ng dng chat c xy dng theo m hnh P2P: va c chc nng Chat server, ng thi c chc nng chat client. ng dng cho php truyn ti file trong qu trnh chat gia hai ngi. ng dng phi h tr v s dng Chat Protocol c m t chi tit nh sau:

Bng 1: M t Chat Protocol c s dng Ghi ch <SESSION_REQ> Client ID</SESSION_REQ> Yu cu khi to mt chat session t pha client. Ch s dng 1 ln cho mi chat session Client ID l id ca ngi s dng pha client <SESSION_ACK> Server ID </SESSION_ACK> Xc nhn yu cu kt ni t pha server. Server id Ch s dng 1 ln cho mi chat session l id ca ngi s dng pha server <CHAT_MSG> Chat message </CHAT_MSG> Gi mt chat message c dng bi c pha server ln client. Chat message ch c th c gi i sau khi client v server ng to chat session. <FILE_REQ> File Name</FILE_REQ> c s dng bi c client v server, sau khi Yu cu chuyn file trong qu trnh chat. File chat session c khi to. Pha chuyn file Name l tn ca file cn chuyn. a ra yu cu <FILE_REQ_ACK> 1 or 0 </FILE_REQ_ACK> Xc nhn yu cu chuyn file t pha nhn. 1 ng Ch c s dng sau khi c c yu cu ; 0 khng ng nhn file. chuyn file. <FILE_DATA_BEGIN /> Bt u chuyn file, c a ra t pha chuyn Qu trnh chuyn file ch c th c thc hin sau khi bn gi v nhn ng . Trong qu trnh chuyn file, hai pha u c th gi nhng chat message. <FILE_DATA> File data unit in binary </FILE_DATA> Ni dung file cn chuyn. Trong trng hp file C th chuyn c file nh phn v file vn ln, file c th ct thnh nhiu on nh v chuyn bn. tng on. <FILE_DATA_END /> Kt thc qu trnh chuyn file. Do pha chuyn a ra. <SESSION_CLOSE /> ng chat session. C th c s dng bi pha Khng th gi c chat message v chuyn client hoc server. file sau khi ng chat session. Nu mt bn a ra yu cu ng, trong khi bn kia vn cn ang chat hoc chuyn file, th d liu khng c x l v b mt. Mc ch s dng

CSER Group | Bo co Assignment 2

Trang 3

Mng My Tnh 1

II.

Thit k chi tit ng dng S packages/classes ca ng dng.

Hnh 1: Thit k class ca ng dng.

CSER Group | Bo co Assignment 2

Trang 4

Mng My Tnh 1

Chng trnh gm hai phn chnh Phn nhn (core): Chu trch nhim thc hin kt ni v x l thng ip. Phn giao din (GUI): Chu trch nhim tng tc vi ngi s dng. 1. Phn nhn (core) Nhim v chnh: - Khi to cu trc chng trnh - To ca s giao din v nhn tng tc t GUI - To Server socket lng nghe ti cng xc nh nhn kt ni - Kt ni vi ng dng pha bn - X l cc thng ip trao i gia hai pha

CSER Group | Bo co Assignment 2

Trang 5

Mng My Tnh 1

Cu trc
Bng 2: Nhim v cc class phn nhn(core).

Nhim v Core / Common - Tag - Util - TagException Core / Chat - MainController


- Khi ti, lu tr, qun l v cho php truy xut n cc ChatGUI v ChatSession sinh ra trong chng trnh. - Khi to, nhn v qun l mt session chat. Khi to cc object cn thit trong qu trnh chat. Tiu hy chng sau khi kt thc. - Thread nhn d liu t pha bn thng qua InputStream. c v phn tch cu trc tag - Cung cp hm giao tip chung gia GUI v Network - Hin thc giao tip pha network - Nhn thng ip t UserChatInterface v gi Tag tng ng n pha bn - Nhn Tag t pha bn v gi phng thc tng ng t UserChatInterface - Hin thc giao din pha GUI - Nhn tng tc t GUI v gi phng thc tng ng t NetworkChatInterface - Nhn thng ip t NetwokChatInterface v th hin ra GUI - Lu tr thng tin tag trao i gia cc class - Cung cp cc chc nng h tr: log, check_userid - Exception xy ra trong qu trnh c, gi tag

Ghi ch
Object ch c Phng thc tnh Exception

Tn ti duy nht trong ton chng trnh. Cho php truy xut bt c lc no bng MainController.it() Mt session tng ng vi mt kt ni gia ng dng v h thng. Session kt thc khi mt trong hai pha ngt kt ni Thread Abstract class Tha k AbsChatInterface

- ChatSession

- InputStreamHandler - AbsChatInterface - NetworkChatInterface

- UserChatInterface

Tha k AbsChatInterface

Core / Server - ServerListener - SClientSocketHandler - ServerException Core / Basic - ChatInterface


- Hin thc tng tc chi tit vi d liu - ReadTag x l ng ngha ca Tag - Khi to FileTransfer Tha k NetworkChatInterface - Thread lng nghe ti cng c th - Khi to SclientSocketHandler khi nhn c kt ni - Thread x l kt ni t pha bn - Khi to ChatSession tng ng vi kt ni - Exception ca server Thread Thread

CSER Group | Bo co Assignment 2

Trang 6

Mng My Tnh 1
- Thread c v ghi file - Hin thc cc protocol m rng

- FileTransfer Core / Extra

Thread

2. Phn giao din (gui) Chu trch nhim tng tc vi ngi s dng: Nhn cc yu cu t ngi dng v tr v kt qu hin th.
Bng 3: Nhim v cc class phn giao din(gui).

GUI - ChatGUI - GUIInterface - LoginGUI - MainGUI

Chc nng
- Giao din Chat vi mi bn chat. - Chu trch nhim tng tc gia ChatGUI v NetworkChatInterface - Giao din ng nhp - Giao din tng tc chnh: nhn cc request t ngi dng: chn ngn ng, kt ni bn Chat

Ghi ch
Tha k UserChatInterface

CSER Group | Bo co Assignment 2

Trang 7

Mng My Tnh 1

III.

Chi tit phng n v qu trnh hin thc ng dng: 1. M t cu trc class


Hnh 2: M t cu trc class. main.P2PChat

core.chat.MainGUI

core.chat.MainController

gui.ChatGUI

core.chat.ChatSession

core.chat.UserChatInterface core.chat.GUIInterface
inherit UserChatInterface

core.chat.NetworkChatInterface core.chat.ChatInterface
inheritNetworkChatInterface

core.basic.FileTransfer

CSER Group | Bo co Assignment 2

Trang 8

Mng My Tnh 1

2. M t cc tin trnh a. Tin trnh server - Sau khi ngi dng ng nhp, thread ServerListerner c khi to v lng nghe trn mt cng ngu nhin. - Khi nhn c kt ni t pha khch, to thread SclientSocketHandler qun l tin trnh chat. Khi to ChatSession tng ng vi kt ni. b. Tin trnh nhn / gi thng ip
UserChatInterface MainGUI User connect initSession recvSesReq ChatGUI MainController.it(). askForChatGUI sesAck recvSesAck NetworkChatInterface initSession recvSesReq SesAck recvSesAck Input / Output Stream Receive SES_REQ Send SES_REQ Receive SES_ACK Send SES_ACK

user input

sendMessage

sendMessage

Receive CHAT_MSG

output to screen

recvMessage

recvMessage

Send CHAT_MSG

Hnh 3: M t tin trnh nhn/ gi thng ip.

NetworkChatInterface v UserChatInterface tha k AbsChatInterface cung cp giao thc thng nht gia GUI v giao thc mng trao i d liu, tng tc gia 2 pha (nh hnh v) c. Tin trnh nhn / gi file - Khi nhn c yu cu gi file, GUI hin hp thoi thng bo cho ngi dng quyt nh nhn file hoc khng. - Vic trao i file din ra. + Pha ngi gi, thread FileTransfer c khi ng lin tc c file v gi d liu n ngi nhn. + Pha ngi nhn, cc d liu <FILE_DATA> c gi n FileTransfer x l v lu file. Trong qu trnh gi, 2 bn vn c th chat bnh thng
CSER Group | Bo co Assignment 2 Trang 9

Mng My Tnh 1

IV.

nh gi kt qu hin thc 1. Kt qu cng vic Hin thc c chng trnh Cat Chat 2010 p ng cc yu cu bi nu ra v mt s chc nng m rng. 2. Kinh nghim thu c: Cc kin thc thu lm c: - Cch thit k v xy dng mt ng dng Desktop hon chnh. - Lp trnh Socket bng Java. - Hnh dung r hn v giao thc kt ni mng(c th y l TCP/IP).

V.

Cc chc nng m rng: 1. Multi-Language: M t: Chng trnh c th chuyn i Ngn ng Anh/ Vit. Ngi dng c th la chn ngn ng Ting Anh hoc Ting Vit khi ng nhp vo chng trnh hoc khi ang Chat. Demo:

CSER Group | Bo co Assignment 2

Trang 10

Mng My Tnh 1

Hnh 4: La chn ngn ng khung ng nhp

CSER Group | Bo co Assignment 2

Trang 11

Mng My Tnh 1

Hnh 5: La chn Ngn ng khung iu khin chnh.

2. Status Icon: M t: Cho php ngi dng c th thit lp cc trng thi lm vic Online/ Offline/ Busy/ Idle bng Icon trng thi. Online Offline Busy Idle Demo:

CSER Group | Bo co Assignment 2

Trang 12

Mng My Tnh 1 Hnh 6: Ngi dng greentea set Status Icon = Busy v c hin th ca s chat vi hungvjnh.

CSER Group | Bo co Assignment 2

Trang 13

Mng My Tnh 1

Hnh 7: Ngi dng greentea set Status Icon = Idle v c hin th ca s chat vi hungvjnh.

CSER Group | Bo co Assignment 2

Trang 14

Mng My Tnh 1

3. Status: M t: Cho php ngi dng m t trng thi c nhn bng mt on text. Demo:
Hnh 8:Ngi dng hungvjnh set trng thi Happy New Year v c hin th 2 ca s ca 2 bn chat greentea v maihuong

CSER Group | Bo co Assignment 2

Trang 15

Mng My Tnh 1

VI.

Hng dn s dng: Bc 1: Khi ng chng trnh Chat: CatChat2010. Chng trnh hin th giao din ng nhp: ng nhp vo chng trnh Chat, nhp tn ngi dng v Click (Login/ ng nhp).

Hnh 9: Giao din ng nhp. chn ngn ng, click vo Ngn ng m bn mun chn(nh hnh v).

CSER Group | Bo co Assignment 2

Trang 16

Mng My Tnh 1

Hnh 10:La chn ngn ng giao din ng nhp. Bc 2: Sau khi ng nhp, chng trnh s c giao din nh sau.

Hnh 11: Giao din iu khin chnh. Chn ngn ng hai flag bn tri, di cng ca khung. CSER Group | Bo co Assignment 2 Trang 17

Mng My Tnh 1

Hnh 12: La chn Ngn ng giao din iu khin chnh.

Bc 3: Nhp IP v port ca bn Chat, click Connect/ Kt ni chat.

Hnh 13: Click Connect/ Kt ni kt ni vi bn chat.

CSER Group | Bo co Assignment 2

Trang 18

Mng My Tnh 1

Hnh 14: Mt giao din ca s chat.

Bt u Chat ^^!

CSER Group | Bo co Assignment 2

Trang 19

Mng My Tnh 1

Thay i Ngn ng:

Hnh 15: Thay i Ngn ng khi ang chat.

CSER Group | Bo co Assignment 2

Trang 20

Mng My Tnh 1

Cm n thy theo di
Nhm CSER

CSER Group | Bo co Assignment 2

Trang 21