Tải bản đầy đủ (.ppt) (18 trang)

báo cáo tiểu luận môn lập trình mạng mô phỏng quá trình làm việc của 2 tcp ip

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (964.49 KB, 18 trang )












 
Đề tài
Đề tài
:
:
MÔ PHỎNG QUÁ TRÌNH LÀM VIỆC CỦA 2 SERVER
MÔ PHỎNG QUÁ TRÌNH LÀM VIỆC CỦA 2 SERVER
NGANG HÀNG TRÊN MẠNG TCP/IP
NGANG HÀNG TRÊN MẠNG TCP/IP


Thực hiện:
Thực hiện:


NGUYỄN HẢI MINH
NGUYỄN HẢI MINH





Lớp KHMT K24
Lớp KHMT K24






Đà Nẵng, 5-2012
Đà Nẵng, 5-2012
2
!
!

 !
 !

"#$%&'(')*+
"#$%&'(')*+

!#!,'-,
!#!,'-,

'!./.'01*+%2*'
'!./.'01*+%2*'

345
345
3

"#!$!%&'
"#!$!%&'

6 !
6 !
",'7*+8-%2*'9 4:!(;<
",'7*+8-%2*'9 4:!(;<
=>3%:3%*+<*+' *+%*4?*+@
=>3%:3%*+<*+' *+%*4?*+@

+'!*A$%&'"*+!(,B%!(
+'!*A$%&'"*+!(,B%!(
+C!DE<8<4?*+
+C!DE<8<4?*+

+'!*A: :!.'01*+%2*'%<5
+'!*A: :!.'01*+%2*'%<5
F!'"*+!(,+!G<=>3%:3%
F!'"*+!(,+!G<=>3%:3%

H,45*!5%!*+I/!I4>5--'"*+
H,45*!5%!*+I/!I4>5--'"*+
!(,.*0%G'"*+!(,.*E)*+
!(,.*0%G'"*+!(,.*E)*+
J<A*+
J<A*+
4
"#!$!%&'())*
"#!$!%&'())*


K
L
,%2*'%*4?*+4-MN*'O*'!
K
L
,%2*'%*4?*+4-MN*'O*'!
>3%:3%
>3%:3%

P'"*+>QRS*+-A*+RS*+9!3*T
P'"*+>QRS*+-A*+RS*+9!3*T
3%:3%O>U*
3%:3%O>U*

",'7*+>V%<5F!'"*+!(,+!G<'<!
",'7*+>V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L
* 0W '"*+ !
L
,B
*'0*+'\O3%:3%* 5Og
*'0*+'\O3%:3%* 5Og









'24Y!'V'!
L
**"
L
!R*+'"*+!
L
,O
'24Y!'V'!
L
**"
L
!R*+'"*+!
L
,O

%*4_!3%:3%O'IE340Wc5*!5%!*+d*h!
%*4_!3%:3%O'IE340Wc5*!5%!*+d*h!
R*+"*+:!(i'V'!(*?!-3%:3%/'-B
R*+"*+:!(i'V'!(*?!-3%:3%/'-B
A9 E340W<>/!>;<3%:3%/'-
A9 E340W<>/!>;<3%:3%/'-

6[*'R?*+;<'"*+!
L
,c3>><+3d
6[*'R?*+;<'"*+!
L

,c3>><+3d
idMessage
idMessage
Stt ca thông
Stt ca thông
đip
đip
IP Server
IP Server
gi
gi
IP Server phi thc
IP Server phi thc
hin
hin
8
,
,

'C*,'*449H,%2*'!%5>5j
'C*,'*449H,%2*'!%5>5j
!><9k<>!lm
!><9k<>!lm

'*44!%5>5jn3>>
'*44!%5>5jn3>>
=mmo
=mmo
9
,())*

,())*

!Y!'!(!/'!I*p!*>5/;<!><9k<>!
!Y!'!(!/'!I*p!*>5/;<!><9k<>!
lm
lm

6!/'!I*q!*>5/'5,'r,/.*)!.*4h4-MN*'D
6!/'!I*q!*>5/'5,'r,/.*)!.*4h4-MN*'D
E<: %<5F!RG9!(>QRS*+4h%5*+'<!+!<5'A
E<: %<5F!RG9!(>QRS*+4h%5*+'<!+!<5'A
c>3%<<+%<4%5559d'5ac%<*>4!>>!5*
c>3%<<+%<4%5559d'5ac%<*>4!>>!5*
5*%59%5559d
5*%59%5559d

O 'I 0W >Q RS*+ I ?5 - A*+ RS*+ 9!3* : 
O 'I 0W >Q RS*+ I ?5 - A*+ RS*+ 9!3* : 
>3%:3%
>3%:3%

?5A*+RS*+9!3*I9$M'"*+!**+0^!RX*+%0Y
?5A*+RS*+9!3*I9$M'"*+!**+0^!RX*+%0Y
/'!+Q!'&*+.*>3%:3%%*+K4
/'!+Q!'&*+.*>3%:3%%*+K4

?5 A*+ RS*+ >3%:3% 4  - 'A *]*+ ;< *O *'0 9 
?5 A*+ RS*+ >3%:3% 4  - 'A *]*+ ;< *O *'0 9 
4h !I4 %*+ K4 ' 'H, RG 9!( D 4h >) *+0^!
4h !I4 %*+ K4 ' 'H, RG 9!( D 4h >) *+0^!

RX*+
RX*+

?5A*+RS*+s'<t
?5A*+RS*+s'<t
10
,())*
,())*

V<'C*+!<5'A
V<'C*+!<5'A

'C*+!<5'A'<Mu
'C*+!<5'A'<Mu

6!I4/'-*'<'N*'+!G<'<!+!<5'A* M*b4g
6!I4/'-*'<'N*'+!G<'<!+!<5'A* M*b4g
%?*+'-!c><3d/.*)!;<'&*+
%?*+'-!c><3d/.*)!;<'&*+
1
234567)89:6);<=>)?5(7@)57AB6C@9*D
234567)89:6);<=>)?5(7@)57AB6C@9*D
1
E5)5>)2FG=>)?5);HI=5)5>);J);67KL5)4)5KHM
E5)5>)2FG=>)?5);HI=5)5>);J);67KL5)4)5KHM
):5ND
):5ND
1
O5PQ)=>)?5KRKHM)S7T4567)8CU45V=>)?5W3
O5PQ)=>)?5KRKHM)S7T4567)8CU45V=>)?5W3

BE7KEP)X)73WYZ69V25N[D
BE7KEP)X)73WYZ69V25N[D
1
!234567)8G5=>)?5(7@)572@CC*D
!234567)8G5=>)?5(7@)572@CC*D
1
\:4567)]45V665P]^ )X45?4H_[6PQ)]5G5>[
\:4567)]45V665P]^)X45?4H_[6PQ)]5G5>[
PQ))4K5NGKHM4`5)aPQ)P]^K>PQ)P]^=]P3
PQ))4K5NGKHM4`5)aPQ)P]^K>PQ)P]^=]P3
=4bPQ)=>)?5;c;3445V6d4D
=4bPQ)=>)?5;c;3445V6d4D

Y!Z !5-** MB'C*+!<5'A
Y!Z !5-** MB'C*+!<5'A
11
,())*
,())*

!Y!'!(*'G*+9(*'1Z#*;<!/'!I*q!*>5/
!Y!'!(*'G*+9(*'1Z#*;<!/'!I*q!*>5/
1. Trên Server 1
1. Trên Server 1
tcpServer1.RemoteHost=
tcpServer1.RemoteHost=
"IP/name"
"IP/name"
Khai báo địa chỉ IP/tên ca Server 2 kết nối với
Khai báo địa chỉ IP/tên ca Server 2 kết nối với
Server 1.

Server 1.
tcpServer1.RemotePort= Port
tcpServer1.RemotePort= Port
No
No
Khai báo địa chỉ cổng ca Server 2 kết nối với
Khai báo địa chỉ cổng ca Server 2 kết nối với
Server 1.
Server 1.
tcpServer1.Connect
tcpServer1.Connect
Server 1 thc hin kết nối vào mạng.
Server 1 thc hin kết nối vào mạng.
tcpServer1.SendData Message
tcpServer1.SendData Message
Server 1 thc hin gi dữ liu (lưu ở biến Message)
Server 1 thc hin gi dữ liu (lưu ở biến Message)
lên mạng.
lên mạng.
tcpServer1.GetData strData
tcpServer1.GetData strData
Server 1 thc hin nhận dữ liu lưu vào biến
Server 1 thc hin nhận dữ liu lưu vào biến
strData.
strData.
tcpServer1.LocalIP
tcpServer1.LocalIP
Chứa địa chỉ IP ca Server 1.
Chứa địa chỉ IP ca Server 1.
12

,())*
,())*

!Y!'!(*'G*+9(*'1Z#*;<!/'!I*q!*>5/cd
!Y!'!(*'G*+9(*'1Z#*;<!/'!I*q!*>5/cd
2. Trên Server 2
2. Trên Server 2
tcpServer2.LocalPort = Port
tcpServer2.LocalPort = Port
No
No
Khai báo địa chỉ cổng ca Server 2 kết nối với
Khai báo địa chỉ cổng ca Server 2 kết nối với
Server 1.
Server 1.
tcpServer2.Listen
tcpServer2.Listen
Server 2 thc hin lắng nghe
Server 2 thc hin lắng nghe
tcpServer2.Accept requestID
tcpServer2.Accept requestID
Server 2 thc hin chấp nhận kết nối.
Server 2 thc hin chấp nhận kết nối.
tcpServer2.SendData Message
tcpServer2.SendData Message
Server 2 thc hin gi dữ liu (lưu ở biến
Server 2 thc hin gi dữ liu (lưu ở biến
Message) lên mạng.
Message) lên mạng.
tcpServer2.GetData strData

tcpServer2.GetData strData
Server 2 thc hin nhận dữ liu lưu vào biến
Server 2 thc hin nhận dữ liu lưu vào biến
strData.
strData.
13
e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