Tìm kiếm dữ liệu trong database

Một phần của tài liệu Bài giảng môn lập trình mạng (Trang 101)

Để tìm kiếm dữ liệu trong bảng của Database chúng ta dựa vào câu lệnh SQL:

“select * from Tenbang where Tencot like ‘%giatri%’ “

Ví dụđoạn chương trình sau cho phép hiển thị những Sinh Viên trong bảng “HosoHV” của DB “Sinhvien.mdb” có tên được tìm kiếm bởi từ khoá “Anh” (Ví dụ : Tuấn Anh, Vân Anh, Việt Anh...) <% set conn=server.createobject("adodb.connection") connstring="provider=microsoft.jet.oledb.4.0;data source="&server.mappath("sinhvien.mdb")&";" conn.open connstring set rs=server.createobject("adodb.recordset")

rs.open "select * from HosoSV where ten like '%Anh%' ",conn

do while not rs.eof

responsẹwrite rs("MaSV") responsẹwrite " " responsẹwrite rs("Ten") responsẹwrite " " responsẹwrite rs("Lop") responsẹwrite "<BR>" rs.movenext loop rs.close %>

Thông thường người sử dụng nhập từ khoá cần tìm kiếm vào một trường của form. như vậy ta chỉ việc dùng lệnh request.form để lấy lại từ khoá cần tìm kiếm và đưa vào câu lệnh SQL ở trên. Chẳng hạn người sử dụng nhập từ khoá cần tìm vào trường “Ten” trong form thì chúng ta sẽ mở bảng bằng câu lệnh SQL sau:

<% ten=request.form(“Ten”)

‘validate

rs.open "select * from HosoSV where Ten like '%”&ten&”%' ",conn

‘... %>

N ếu không tìm thấy bản ghi nào thì giá trị rs.EOF sẽ truẹ

<%

ng

PH LC

Phụ lục 1: Bài tập truy nhập các điều khiển trên Form Yêu cầu: - Thiết kế Form như hình 1 dưới đây

- Sau khi nhập thông tin trên Form nhất nút Xem sẽ cho ra kết quả như hình 2

Hình 1 File Nhap.asp <html> <head>

<meta http-equiv="Content-Language" content="en-us">

<meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title>Ho va ten</title>

</head>

ng

<body>

<form method="POST" action="xuly_nhap.asp">

<table border="1" width="53%" id="table1" bgcolor="#C0C0C0"> <tr> <td width="107">Ho va ten</td>

<td><input type="text" name="txthoten" size="20"></td> </tr> <tr>

<td width="107">Gioi tinh</td>

<td><input type="radio" value="N am" checked name="rdogt">N am <input type="radio" name="rdogt" value="N u">N u</td>

</tr> <tr>

<td width="107">N gay sinh</td> <td>

N gay<select size="1" name="optN gay"> <%for i=1 to 31%>

<option value=<%=i%>><%=i%></option> <%N ext%>

</select>

Thang<select size="1" name="optthang"> <%for i=1 to 12%>

<option value=<%=i%>><%=i%></option> <%N ext%>

</select>

N am<select size="1" name="optN am"> <%for i=1970 to year(date())%>

<option value=<%=i%>><%=i%></option> <%N ext%>

</select></td> </tr>

<tr>

<td width="107" height="53">So thich</td> <td height="53">

<input type="checkbox" name="chksothich" value="Du lich">Du lich <input type="checkbox" name="chksothich" value="The thao">The thao <input type="checkbox" name="chksothich" value="Ca nhac"> Ca nhac <p><input type="checkbox" name="chksothich" value="Tin hoc"> Tin hoc <input type="checkbox" name="chksothich" value="N au an"> N au an<input type="checkbox" name="chksothich" value="Mua sam"> Mua sam</td>

</tr> <tr>

<td width="107">Ghi chu</td>

<td><textarea rows="6" name="txtaGhichu" cols="29"></textarea></td> </tr>

</table>

<input type="submit" value=" Xem " name="cmdXem"> <input type="reset" value="N hap lai" name="cmdnhaplai"> </form>

</body> </html>

ng

File Xuly_nhap.asp

<%

responsẹwrite "Ho va ten: " & request.form("txthoten") & "<br>" responsẹwrite "Gioi tinh: " & request.form("rdogt") & "<br>"

ngaysinh=request.form("optngay") & "/" & request.form("optthang") & "/" &

request.form("optnam") responsẹwrite "N gay sinh: " & N gaysinh & "<br>"

responsẹwrite "So thich: " & & request.form("chksothich") & "<br>" responsẹwrite "Ghi chu: " & request.form("txtaGhichu") & "<br>" %>

<a href=nhap.asp>Quay lai</a>

Phụ lục 2: Thiết kế form đăng nhập cho phép lưu lại tên tài khoản và mật khẩu

1. Yêu cầu: - Thiết kế Form đăng nhập (hình trái), cho phép lưu lại tài khoản. N ếu đăng nhập thành công thì mở ra trang Homẹasp (hình phải)

File Login.asp

<html> <head>

<meta http-equiv="Content-Language" content="en-us">

<meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title>User name</title>

</head> <body> <%

'Kiem tra neu da co Cookies thi dang nhap luon vao trang Homẹasp

if request.cookies("Acc")("user")="Admin" and request.cookies("Acc")("pass")="12345" then responsẹredirect("Homẹasp")

ng

else

'N eu chua co Cookies thi cho hien giao dien dang nhap %>

<form method="POST" action="login.asp">

<table border="1" width="56%" id="table1" bgcolor="#C0C0C0"> <tr>

<td width="129" height="35"><b>User name</b></td> <td height="35">

<input name="txtUser" size="20"></td> </tr>

<tr>

<td width="129" height="33"><b>Password</b></td> <td height="33">

<input type="password" name="txtPass" size="19"></td> </tr>

<tr>

<td colspan="2">

<input type="checkbox" name="chkSave" value="ON "> <b>Remember your account</b>

</td> </tr> </table>

<input type="submit" value=" Login " name="CmdLogin"> </form>

<%

'N eu tai khoan dang nhap chinh xac thi cho vaò trang Homẹasp

if request.form("txtuser")="Admin" and request.form("txtpass")="12345" then 'N eu check luu lai thong tin ve tai khoan thi tao Cookies de luu

if request.form("chkSave")<>"" then 'Tao Cookies luu lai taì khoan

responsẹcookies("Acc")("User")="Admin" responsẹcookies("Acc")("pass")="12345"

'Dat thoi han ton tai cua Cookies la 5 ngay ke tu ngay hien tai responsẹcookies("Acc").expires=date()+5

end if

responsẹredirect("Homẹasp") else

'Tai khoan dang nhap khong chinh xac thi bao loi if request.form("cmdLogin")<>"" then

responsẹwrite "Login error...!"

end if end if end if %> </body> </html> File Homẹasp <html> <head>

ng

<meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title>Login successfull</title>

</head> <body>

<p><b>Login successful !</b></p>

<form method="POST" action="Homẹasp">

<p>Do you want <input type="submit" value="Logout" name="cmdLogout"></p> </form>

<%

'N han Logout de huy Cookies

if request.form("cmdLogout")<>"" then

responsẹcookies("Acc")("user")="" responsẹcookies("Acc")("pass")="" 'Khong dung` Expires thi Cookies se bi huy 'ngay sau khi dong IE hien hanh`

responsẹredirect("Login1.asp") end if %> </body> </html> 2. Nâng cấp chương trình:

Yêu cầu kiểm tra tài khoản đang nhập có tồn tại trong CSDL không. Làm theo các bước sau:

(1) Tạo CSDL HOSỌMDB và bảng Account(ID(Autonumber), User(Text), Pass(Text)) (2) Viết file Connection.inc kết nối tới CSDL

Connection.inc

<%

Set Conn=Server.CreateObject("ADODB.Connection") FilePath= Server.Mappath("Hosọmdb")

StrConn="Provider=Microsoft.Jet.OLEDB.4.0; Data source=" & FilePath Conn.Open StrConn

Set RS=Server.CreateObject("ADODB.Recordset") %>

(3) Chèn đoạn mã sau đây vào trước thẻ <HTML> trong file Login.asp

<!--#include file=Connection.inc--> <%

ID=request.cookies("Acc")("user") PWD=request.cookies("Acc")("Pass")

'Mo bang du lieu Account va chon ra dung TK da luu trong Cookies

StrSQL="Select * from Account Where (User='" & ID & "')AN D(Pass='" & PWD & "')" RS.Open StrSQL,Conn

%>

(4) Sửa lại dòng gạch chân sau thẻ <BODY> như sau:

<%

'Kiem tra neu da co Cookies thi dang nhap luon vao trang Homẹasp If not rs.eof then

responsẹredirect("Homẹasp") else

'N eu chua co Cookies thi cho hien giao dien dang nhap %>

ng

**************************************************

Phụ lục 3: Hiển thị ảnh quảng cáo và số lượt truy cập

Yêu cầu cho phép:

- Đếm số lượt người đã truy cập - Hiển thị ảnh quảng cáo ngẫu nhiên Yêu cầu: Sử dụng file Global.asa

(Ghi chú: Chuẩn bị sẵn 3 ảnh: 1.gif, 2.gif, 3.gif)

File Global.asa

<OBJECT ID="Dem" RUNAT="Server" SCOPE="Application"

PROGID="MSWC.Counters"> </OBJECT>

<OBJECT ID="Pic" RUNAT="Server" SCOPE="Application"

PROGID="MSWC.Adrotator"> </OBJECT>

File Quangcaọasp

<%

responsẹwrite "So luot ttruy cap website la:" %> <% dem.Increment("k") responsẹwrite dem.get("k") %> <br> <% =pic.GetAdvertisement("quangcaọtxt") ‘noi dung file quangcaọtxt nhu tren %> File Quangcaọtxt REDIRECT /login.asp WIDTH 300 HEIGHT 300 BORDER 1 * 1.gif http://homẹvnn.vn Trang chu Viet Nam 60 2.gif http://vbcodẹcom Ma nguon VB 40 3.gif http://www.vnexprepss.net Trang tin tuc

ng

Phụ lục 4: Bài tập ADO, Phân trang với Recordset

1. Tạo CSDL HOSỌMDB và thiết kế các bảng dữ liệu có cấu trúc như sau:

Tạo quan hệ giữa 2 bảng như sau:

2. Thiết kế trang DEFAULT.ASP cho phép hiển thị các thông tin về sinh viên như sau:

Chú ý:

- Sử dụng kỹ thuật phân trang

- Các chức năng AĐ, EDIT, DELETE để thực hiên các chức năng thêm mới, sửa, xóa các bản ghi

- Nhấn vào Mã SV cho phép liên kết đến trang xem tổng hợp thông tin cá nhân về SV đó (Ví dụ: Profilẹasp)

Bảng Sinhvien

ng

3. Yêu cầu thiết giao diện các trang thêm mới và sửa như sau:

- Giao diện cập nhật SV mới

- Giao diện thay đổi thông tin cá nhân 1 SV đã nhập

MÃ NGUỒN MẦU File Connection.inc <% FilePath=Server.Mappath("Hosọmdb") Set Conn=Server.CreateObject("ADODB.COnnection")

StrConn="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & FilePath Conn.Open strConn Set RS=Server.CreateObject("ADODB.Recordset") %> File Default.asp <!--#include file=Connection.inc--> <%

'Su dung Query trong Access de tao xau truy van nhu duoi day

StrSQL="SELECT SinhVien.*, [Tinh].[Tentinh] FROM Tinh INNER JOIN SinhVien ON [Tinh].[MaTinh]=[SinhVien].[MaTinh];"

'Dat thuoc tinh cho RS co kha nang phan trang RS.CursorLocation=3

RS.Pagesize=3

RS.Open StrSQL,Conn,0,1 'Xac dinh trang hien thoi Session("CurrenPage")=1 If request("PageID")<>"" then

Session("CurrenPage")=Cint(request("PageID")) End if

If not(RS.eof or RS.bof) then

RS.Absolutepage=Session("CurrenPage") End if

ng

<head>

<meta http-equiv="Content-Language" content="en-us">

<meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <meta name="GENERATOR" content="Microsoft FrontPage 6.0">

<meta name="ProgId" content="FrontPagẹEditor.Document"> <title>Phân trang với RS</title>

</head> <body>

<p align="center"><b>DANH SACH SINH VIEN </b></p> <form method="POST" action="Xuly_Default.asp">

<b>Page <%=Session("CurrenPage")%> of <%=RS.PageCount%></b> <table border="0" width="100%">

<tr> <td>STT</td> <td>Sửa</td> <td>Xóa</td> <td>Mã SV</td> <td>Họ và tên</td> <td>Giới tính</td> <td>Tuổi</td>

<td>Ngày vào đoàn</td> <td>Tên Tỉnh</td> <td>Sở thích</td> </tr>

<%

i=RS.Pagesize*(Session("CurrenPage")-1)

While not RS.eof and RS.AbsolutePage=Session("CurrenPage") i=i+1

%> <tr>

<td><%=i%></td>

<td><input type="radio" value=<%=RS.Fields("MaSV")%> checked name="RdoSua"></td> <td><input type="checkbox" name="chkXoa" value=<%=RS.Fields("MaSV")%>></td> <td> <a href=Profilẹasp?MaSV_ID=<%=RS.Fields("MaSV")%>><%=RS.Fields("MaSV")%></a> </td> <td><%=RS.Fields("Hoten")%></td> <td width="6%" align="center"> <% If RS.Fields("Gioitinh") then ResponsẹWrite("Nam") Else ResponsẹWrite("Nu") End if %> </td> <td width="6%" align="center"><%=RS.Fields("Tuoi")%></td> <td width="9%"><%=RS.Fields("NgayDoan")%></td> <td width="10%"><%=RS.Fields("Tentinh")%></td> <td width="29%"><%=RS.Fields("Sothich")%></td> </tr> <% RS.MoveNext Wend %> </table>

<table border="0" width="100%"> <tr>

<td width="23%">

<%If Session("CurrenPage")=1 then Responsẹwrite("Back") Else%>

ng <a href=Default.asp?PageID=<%=Session("CurrenPage")-1%>>Back</a> <%End if%> </td> <td width="54%"> <p align="center"> <% k1=Session("CurrenPage")-1 k2=Session("CurrenPage")+1 If k1<1 then k1=1

If k2>RS.PageCount then k2=RS.PageCount For i=k1 to k2 Responsẹwrite (" ") If i=Session("CurrenPage") then Responsẹwrite(i) Else%> <a href=Default.asp?PageID=<%=i%>><%=i%></a> <%End if Next %> </td> <td width="23%"> <p align="right">

<%If Session("CurrenPage")=RS.PageCount then Responsẹwrite("Next") Else%> <a href=Default.asp?PageID=<%=Session("CurrenPage")+1%>>Next</a> <%End if RS.Close %> </td> </tr> </table>

<input type="submit" value="Ađ" name="cmdAđ"> <input type="submit" value="Edit" name="cmdEdit"> <input type="submit" value="Delete" name="cmdDelete"> </form> </body> </html> File Xuly_Default.asp <% if request.form("cmdAđ")<>"" then responsẹredirect("Them.asp") end if if request.form("cmdEdit")<>"" then session("MaSV")=request.form("rdoSua") responsẹredirect("Suạasp") end if if request.form("cmdDelete")<>"" then %> <!--#include file=xoạasp--> <% end if %> File Them.asp <!--#include file=Connection.inc--> <%

StrSQL="Select * from Tinh Order By Tentinh" RS.Open StrSQL,Conn

%> <html> <head>

<meta http-equiv="Content-Language" content="en-us">

ng

<meta name="GENERATOR" content="Microsoft FrontPage 6.0"> <meta name="ProgId" content="FrontPagẹEditor.Document"> <title>Thêm mới SV</title>

</head> <body>

<form method="POST" action="Xuly_them.asp"> <b>CẬP NHẬT SINH VIÊN</b>

<table border="0" width="61%">

<tr><td>Mã SV</td><input type="text" name="txtMaSV" size="12"></td></tr> <tr><td>HỌ và tên</td><td><input type="text" name="txtHoten" size="30"></td></tr> <tr>

<td>Giới tính</td>

<td><input type="radio" value="Nam" checked name="rdoGT">Nam <input type="radio" name="rdoGT" value="Nu">Nữ

</td>

</tr> <tr><td>Tuổi</td><td><input type="text" name="txtTuoi" size="12"></td> </tr> <tr> <td>Ngày vào đoàn</td>

<td>

<select size="1" name="optNgay"> <%For i=1 to 31%>

<option <%if i=day(date()) then%> selected <%End if%> value=<%=i%>><%=i%></option> <%Next%>

</select>

<select size="1" name="optThang"> <%For i=1 to 12%>

<option <%if i=month(date()) then%> selected <%End if%> value=<%=i%>><%=i%></option> <%Next%>

</select>

<select size="1" name="optNam"> <%For i=1970 to year(date())%>

<option selected value=<%=i%>><%=i%></option> <%Next%> </select></td> </tr> <tr> <td>Tỉnh</td> <td>

<select size="1" name="optTinh"> <%

While not Rs.eof %> <option value=<%=RS.Fields("Matinh")%>><%=RS.Fields("TenTinh")%></option> <% RS.MoveNext Wend RS.Close %> </select></td> </tr> <tr> <td>Sở thích</td>

<td><input type="checkbox" name="chkST" value="Du lich">Du lịch <input type="checkbox" name="chkST" value="The thao">Thể thao <input type="checkbox" name="chkST" value="Xem TV">Xem TV <input type="checkbox" name="chkST" value="Ca nhac">Ca nhạc </td>

</tr>

<tr> <td><input type="submit" value="Save" name="CmdSave"> <input type="reset" value="Reset" name="cmdReset"></td> </tr>

ng </form> </body> </html> File Xuly_them.asp <!--#include file=Connection.inc--> <%

StrSQL="Select * from Sinhvien" RS.Open StrSQL,Conn,1,3 RS.AđNew RS.Fields("MaSV")=request.form("txtMaSV") RS.Fields("Hoten")=request.form("txtHoten") RS.Fields("MaSV")=request.form("txtMaSV") If Request.form("rdoGT")="Nam" then RS.Fields("Gioitinh")=True else RS.Fields("Gioitinh")=False End if RS.Fields("Tuoi")=request.form("txtTuoi") ND=request.form("optThang")&"/"&request.form("optNgay")&"/"&request.form("optNam") RS.Fields("NgayDoan")=Cdate(ND) RS.Fields("Matinh")=request.form("optTinh") RS.Fields("Sothich")=request.form("chkST") RS.Update RS.Close responsẹredirect("Default.asp") %> File Suạasp <!--#include file=Connection.inc--> <%

StrSQL="Select * from Tinh Order By Tentinh" RS.Open StrSQL,Conn

StrSQL1="Select * from Sinhvien Where MaSV='" & session("MaSV") & "'" Set RS1=Server.CreateObject("ADODB.Recordset")

RS1.Open StrSQL1,Conn %>

<html> <head>

<meta http-equiv="Content-Language" content="en-us">

<meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <meta name="GENERATOR" content="Microsoft FrontPage 6.0">

<meta name="ProgId" content="FrontPagẹEditor.Document"> <title>Sửa thông tin SV</title>

</head> <body>

<form method="POST" action="Xuly_Suạasp"> <b>SUA THÔNG TIN SINH VIÊN</b>

<table border="0" width="61%">

<tr><td>Mã SV</td> <td><%=RS1.Fields("MaSV")%></td> </tr> <tr>

<td>Họ và tên</td> <td>

<input type="text" name="txtHoten" size="30" value=<%="'"&RS1.Fields("Hoten")&"'"%>> </td>

</tr> <tr>

<td>Giới tính</td> <td>

<input type="radio" value="Nam" <%if rs1.fields("Gioitinh") then%> checked <%End if%> name="rdoGT">Nam

ng

<input type="radio" name="rdoGT" <%if Not rs1.fields("Gioitinh") then%> checked <%End if%> value="Nu">Nữ

</td> </tr> <tr>

<td>Tuổi</td>

<td><input type="text" name="txtTuoi" size="12" value=<%=rs1.fields("Tuoi")%>></td> </tr>

<tr>

<td>Ngày vào đoàn</td> <td>

<select size="1" name="optNgay"> <%For i=1 to 31%>

<option <%if i=day(rs1.fields("Ngaydoan")) then%> selected <%End if%> value=<%=i%>><%=i%></option>

<%Next%> </select>

<select size="1" name="optThang"> <%For i=1 to 12%>

<option <%if i=Month(rs1.fields("Ngaydoan")) then%> selected <%End if%> value=<%=i%>><%=i%></option>

<%Next%> </select>

<select size="1" name="optNam"> <%For i=1970 to year(date())%>

<option <%if i=year(rs1.fields("Ngaydoan")) then%> selected <%End if%> value=<%=i%>><%=i%></option> <%Next%> </select></td> </tr> <tr><td>Tỉnh</td> <td>

<select size="1" name="optTinh"> <%

While not Rs.eof %>

<option <%if RS.Fields("Matinh")=RS1.Fields("Matinh") then%> Selected <%End if%> value=<%=RS.Fields("Matinh")%>><%=RS.Fields("TenTinh")%></option> <% RS.MoveNext Wend %> </select></td> </tr> <tr> <td>Sở thích</td> <td>

<input type="checkbox" name="chkST" value="Du lich" <%if

instr(Ucase(rs1.fields("Sothich")),ucase("Du lich"))>0 then%> checked <%End if%>>Du lịch <input type="checkbox" name="chkST" value="The thao" <%if

instr(Ucase(rs1.fields("Sothich")),ucase("The thao"))>0 then%> checked <%End if%>>Thể thao <input type="checkbox" name="chkST" value="Xem TV" <%if

instr(ucase(rs1.fields("Sothich")),ucase("Xem TV"))>0 then%> checked <%End if%>>Xem TV <input type="checkbox" name="chkST" value="Ca nhac" <%if

instr(ucase(rs1.fields("Sothich")),ucase("Ca nhac"))>0 then%> checked <%End if%>>Ca nhạc</td> </tr>

<tr>

<td><input type="submit" value="Save" name="CmdSave"> <input type="reset" value="Reset" name="cmdReset"> </td>

</tr> </table> </form>

ng <% rs.Close rs1.Close %> </body> </html> File Xuly_suạasp <!--#include file=Connection.inc--> <%

StrSQL="Select * from Sinhvien Where MaSV='" & session("MaSV") & "'" RS.Open StrSQL,Conn,1,3 RS.Fields("Hoten")=request.form("txtHoten") If Request.form("rdoGT")="Nam" then RS.Fields("Gioitinh")=True else RS.Fields("Gioitinh")=False End if RS.Fields("Tuoi")=request.form("txtTuoi") ND=request.form("optThang")&"/"&request.form("optNgay")&"/"&request.form("optNam") RS.Fields("NgayDoan")=Cdate(ND) RS.Fields("Matinh")=request.form("optTinh") RS.Fields("Sothich")=request.form("chkST") RS.Update RS.Close responsẹredirect("Default.asp") %> File Xoạasp <!--#include file=Connection.inc--> <%

For i=1 to request.form("chkXoa").Count If request.form("chkXoa")(i)<>"" then

StrSQL="Select * from SinhVien Where MaSV='" & request.form("chkXoa")(i) & "'"

RS.Open StrSQL,Conn,1,3 RS.Delete RS.Close end if next Responsẹredirect("Default.asp") %> File Profilẹasp <!--#include file=Connection.inc--> <%

StrSQL="SELECT SinhVien.*, Tinh.* FROM Tinh INNER JOIN SinhVien ON

[Tinh].[MaTinh]=[SinhVien].[MaTinh] WHERE MaSV=' " & request("MaSV_ID") & " ' “ RS.Open StrSQL,Conn

Responsẹwrite "Mã SV: " & RS.fields("MaSV") & "<BR>" Responsẹwrite "Họ tên: " & RS.fields("Hoten") & "<BR>" Responsẹwrite "Giới tính: "

If rs.fields("Gioitinh") then

Responsẹwrite "Nam" & "<BR>" else

Responsẹwrite "Nữ" & "<BR>" end if

Responsẹwrite "Tuổi: " & RS.fields("Tuoi") & "<BR>"

Responsẹwrite "Ngày vào đoàn: " & RS.fields("Ngaydoan") & "<BR>" Responsẹwrite "Tỉnh/Tp: " & RS.fields("Tentinh") & "<BR>"

Responsẹwrite "Sở thích: " & RS.fields("Sothich") & "<BR>" %>

Một phần của tài liệu Bài giảng môn lập trình mạng (Trang 101)