МІНІСТЕРСТВО ОСВІТИ І НАУКИ УКРАЇНИ p>
ТАВРІЙСЬКИЙ НАЦІОНАЛЬНИЙ УНІВЕРСИТЕТ ім. В. І. Вернандского p>
МАТЕМАТИЧНИЙ ФАКУЛЬТЕТ p>
КАФЕДРА ІНФОРМАТИКИ p>
ДИПЛОМНА РОБОТА p>
Проектування та розробка мережевих броузерів на основі теоретико-Графова моделей p>
Виконав студент 5 курсу p>
спеціальності «інформатика» p>
_________________Поляков Т.І. p>
Науковий керівник, к.ф. - м . н., доцент p>
___________________Попов В.Б. p>
Рішення про допуск до захисту: p>
_________________________ p>
Зав.кафедри інформатики
д.ф.-м.н., професор p>
________________Донской В.І. p>
Сімферополь p>
2000 p >
| Зміст | |
| Вступ | 2 |
| | |
| Глава I. Теоретико-Графова моделі організації мережевих | 3 |
| структур | |
| | |
| 1.1. Основні поняття теорії графів | 3 |
| | |
| 1.2. Графова алгоритми | 5 |
| Глава II. Мережеві структури на базі теоретико-Графова | 11 |
| моделей | |
| 2.1. Методи побудови мережевих структур | 11 |
| 2.2. Класифікація існуючих методів | 12 |
| організації мереж | |
| 2.3. Глобальна мережа Internet | 16 |
| 2.4. Основи мережевої маршрутизації | 20 |
| 2.5. Алгоритми маршрутизації | 24 |
| Глава III. Мережеві броузери | 33 |
| 3.1. Опис стандартного броузера | 33 |
| 3.2. Характеристика існуючих систем пошуку | 33 |
| 3.3. Особливості створення броузерів в | 40 |
| візуальних середовищах | |
| | |
| програмування | |
| | |
| Глава??. Програмна реалізація | 44 |
| | |
| 4.1. Архітектура системи "броузер" | 44 |
| | |
| 4.2. Основні процедури броузера | 45 |
| | |
| 4.3. Архітектура імітаційної моделі глобальної мережі | 47 |
| | |
| 4.4. Основні процедури імітаційної моделі | 48 |
| | |
| Висновок | 50 |
| | |
| Список літератури | 51 |
| | |
| Додаток 1 - вихідний текст програми "броузер" | 52 |
| | |
| Додаток 2 - вихідний текст моделі корпоративної мережі | 91 | p>
Введення p>
Актуальність p>
У зв'язку з розширенням глобальної мережі Internet зростає необхідністьвпровадження нових оптимізаційних алгоритмів, пов'язаних зі швидкістю обмінуданих між комп'ютерами в єдиній мережі. Комп'ютерні мережі завойовують світ.
Системи з маленьких комп'ютерів перетворюються у величезні сховища даних,доступні всьому світу. Будь-яка сучасна фірма, будь-який офіс оснащений хоча бнайпростішою мережею. Не виходячи з дому, сотні тисяч людей працюють наперсональних комп'ютерах, на користь всьому світу. В основному для роботив Internet використовуються програми-броузери. Ці програми дозволяють легкообмінюватися текстової, графічної та звуковою інформацією, використовуючипопулярну, просту в обігу мультемедійную службу ІНТЕРНЕТ World Wide
Web. P>
Мета p>
Мета даної роботи полягає в наступному: p>
- розробка математичної моделі мережевого оглядача і корпоративноїсередовища; p>
- створення імітаційної моделі розподіл інформації в глобальнихмережах. p>
Для досягнення даної мети були вирішені наступні завдання: p>
1.) Проведено аналіз існуючих броузерів; p>
2.) Розглянуто основні топології існуючих корпоративних мереж; p>
3.) Розроблено алгоритм визначення оптимального маршруту передачі p>
інформації по глобальній мережі. p>
1.Теоретіко - Графова моделі організації мережевих структур p>
1.1. Основні поняття теорії графів p>
Визначення. Безліч Х = і набір U невпорядкованих пар об'єктів
() З Х називається графом Г. Об'єкти множини Х називаються вершинамиграфа, а набори об'єкта U - ребрами графа. Про ребра будемо говорити,що вони з'єднують вершини і. У випадку, якщо безліч Х інабір U складаються з кінцевого числа об'єктів і пар, то граф Г називаєтьсякінцевим. p>
Нехай і - довільні вершини графа Г. p>
Визначення. Система ребер графа Г називається шляхом, що з'єднує вершини та. P>
Определеніе.Путь, що не проходить двічі одне ребро, називаєтьсяциклом, якщо =. Зокрема, цикл будемо називати петлею. P>
Визначення. Граф Г називається зв'язковим, якщо для будь-яких двох різних p>
вершин і графа Г існує шлях, що з'єднує ці вершини. P>
Рис. 1 p>
Легко бачити, що граф з прикладу 1 є кінцевим, незв'язних іщо містить петлі. p>
Визначення. графи Г і Г `називаються ізоморфні, якщо існуєвзаємно однозначна відповідність між їх вершинами і ребрами таке, щовідповідні ребра з'єднують відповідні вершини. p>
Визначення. Граф Г `називається подграфом Г, якщо його вершини і ребраналежать графу Г. p>
Завдовжки шляху в графі називають суму довжин що входять в цей шлях ребер. p>
Визначення. Деревом називається кінцевий зв'язний граф з виділеноювершиною, що іменується коренем, що не містить циклів. p>
Якщо в графі можна виділити більше одного дерева, які не пов'язні міжсобою, то такий граф називають лісом. p>
Рис 2. Ліс, що має два компоненти зв'язності (2 дерева). P>
Будемо далі позначати через Х - безліч вершин і U - безліч реберграфа, а сам граф, який визначається цією парою об'єктів, будемо позначати
;x? X, u? U. Позначимо довжину дуги u = (x, y) через d (u). Найкоротшу довжину шляхуз х в p>
z позначимо D (x, z). p>
Очевидно, якщо найкоротший шлях з x в z існує і проходить черезпроміжну вершину w, то D (x, z) = D (x, w) + D (w, z). Ця формуласправедлива для будь-якої проміжної вершини w розглянутого шляхи, у томучислі і для останньої, суміжній з кінцевою вершиною w. Тому найкоротшийшлях можна відшукати, послідовно переходячи від кінцевої вершини z внайближчу суміжну і запам'ятовуючи ланцюжок побудованих вершин (звичайно, заумови, що хоча б один шлях між вершинами x і z існує і граф немістить циклів. Ця ідея і є по суті принципом Р. Беллмана. P>
1.2. Графова алгоритми p>
Алгоритм Беллмана пошуку найкоротшого шляху між двома вершинами зв'язковогографа, що не має циклів з невід'ємними довжинами ребер. Його описнаводиться нижче за допомогою алгоритмічної схеми. p>
Ідентифікатори: p>
D [w] - робочий масив, при обчисленнях інтерпретується як найкоротшадовжина з вершини w в вершину z. w? X. d [s, t] - масив довжин ребер графа для кожної пари вершин s, t? X. Якщодеяке ребро відсутній, то в елементі цього масиву покладаєтьсязаписаним деякий достатньо велика кількість, що перевищує суму довжин всіхребер графа. p>
Stack - послідовність вершин, що визначає найкоротший шлях з x вz. p>
Begin p>
Stack :='';// Очистити Stack. p>
Stack 0 then with ClientSocket do begin p>
Host : = Server; p>
Active: = True; end; end; p>
procedure TChatForm.Exit1Click (Sender: TObject); begin p>
ServerSocket.Close;
ClientSocket.Close; p>
Close; end; p>
procedure TChatForm.Memo1KeyDown (Sender: TObject; var Key: Word; p>
Shift : TShiftState); begin if Key = VK_Return then if IsServer then p>
ServerSocket.Socket.Connections [0]. SendText (Memo1.Lines [Memo1.Lines.Count -
1]) else p>
ClientSocket.Socket.SendText (Memo1.Lines [Memo1.Lines.Count - 1]); end; p>
procedure TChatForm.FormCreate (Sender: TObject); begin p>
FileListenItemClick (nil); end; p>
procedure TChatForm.ServerSocketError (Sender: TObject; Number: Smallint; var Description: string; Scode: Integer; const Source, HelpFile:string; p>
HelpContext: Integer; var CancelDisplay: Wordbool); begin p>
ShowMessage (Description); end; p>
procedure TChatForm.Disconnect1Click (Sender: TObject) ; begin p>
ClientSocket.Close; p>
FileListenItemClick (nil); end; p>
procedure TChatForm.ClientSocketConnect (Sender: TObject; p>
Socket: TCustomWinSocket); begin p>
Statusbar1.Panels [0]. Text: = 'Connected to:' + Socket.RemoteHost; end; p>
procedure TChatForm.ClientSocketRead (Sender: TObject ; p>
Socket: TCustomWinSocket); begin p>
Memo2.Lines.Add (Socket.ReceiveText); end; p>
procedure TChatForm.ServerSocketClientRead (Sender: TObject; p>
Socket: TCustomWinSocket); begin p>
Memo2.Lines.Add (Socket.ReceiveText); end; p>
procedure TChatForm.ServerSocketAccept (Sender: TObject;
Socket: TCustomWinSocket); begin p>
IsServer: = True; p>
Statusbar1.Panels [0]. Text: = 'Connected to:' + Socket.RemoteAddress ; end; p>
procedure TChatForm.ServerSocketClientConnect (Sender: TObject; p>
Socket: TCustomWinSocket); begin p>
Memo2.Lines.Clear; end; p >
procedure TChatForm.ClientSocketDisconnect (Sender: TObject; p>
Socket: TCustomWinSocket); begin p>
FileListenItemClick (nil); end; p>
procedure TChatForm. ClientSocketError (Sender: TObject; p>
Socket: TCustomWinSocket; ErrorEvent: TErrorEvent; var ErrorCode: Integer); begin p>
Memo2.Lines.Add ( 'Error connecting to:' + Server) ; p>
ErrorCode: = 0; end; p>
procedure TChatForm.ServerSocketClientDisconnect (Sender: TObject; p>
Socket: TCustomWinSocket); begin p>
ServerSocket.Active: = False; p>
FileListenItem.Checked: = not FileListenItem.Checked; p>
FileListenItemClick (nil); end; p>
end. p>
файл ftp.pas p>
unit ftp; p>
interface p>
uses p>
Windows, Messages, SysUtils, Classes Graphics, Controls, Forms,
Dialogs, p>
Buttons, StdCtrls, ComCtrls, OleCtrls, Menus, ExtCtrls, isp3; p>
const p>
FTPServer = 0; p>
Folder = 1; p>
OpenFolder = 2; p>
type p>
TMyFtp = class (TForm) p>
Bevel1: TBevel; p>
Panel1: TPanel; p>
Panel2: TPanel; p>
Panel3: TPanel; p>
StatusBar: TStatusBar; p>
FileList: TListView ; p>
DirTree: TTreeView; p>
ConnectBtn: TSpeedButton; p>
FTP: TFTP; p>
RefreshBtn: TSpeedButton; p> < p> MainMenu1: TMainMenu; p>
FileMenu: TMenuItem; p>
FileNewItem: TMenuItem; p>
FileDeleteItem: TMenuItem; p>
FileRenameItem: TMenuItem; p>
N2: TMenuItem; p>
FileExitItem: TMenuItem; p>
View1: TMenuItem; p>
ViewLargeItem: TMenuItem; p>
ViewSmallItem: TMenuItem; p>
ViewListItem: TMenuItem; p>
ViewDetailsItem: TMenuItem; p>
N1: TMenuItem; p>
ViewRefreshItem: TMenuItem;
FilePopup: TPopupMenu; p>
DeleteItem: TMenuItem; p>
RenameItem: TMenuItem; p>
CopyItem: TMenuItem; p>
Bevel2: TBevel; p>
Label1: TLabel; p>
Bevel3: TBevel; p>
Bevel5: TBevel; p>
Label2: TLabel; p>
SaveDialog1: TSaveDialog; p>
CopyButton: TSpeedButton; p>
LargeBtn: TSpeedButton; p>
SmallBtn: TSpeedButton; p>
ListBtn : TSpeedButton; p>
DetailsBtn: TSpeedButton; p>
Tools1: TMenuItem; p>
ToolsConnectItem: TMenuItem; p>
ToolsDisconnectItem: TMenuItem; p >
FileCopyItem: TMenuItem; p>
PasteFromItem: TMenuItem; p>
OpenDialog1: TOpenDialog; p>
SmallImages: TImageList; procedure ConnectBtnClick (Sender: TObject); procedure FTPProtocolStateChanged (Sender: TObject; p>
ProtocolState: Smallint); procedure FormClose (Sender: TObject; var Action: TCloseAction); procedure FormCreate (Sender: TObject); procedure FTPBusy (Sender: TObject; isBusy: Wordbool) ; procedure DirTreeChange (Sender: TObject; Node: TTreeNode); procedure RefreshBtnClick (Sender: TObject); procedure DirTreeChanging (Sender: TObject; Node: TTreeNode; var AllowChange: Boolean); procedure FTPStateChanged (Sender: TObject; State: Smallint); procedure Open1Click (Sender: TObject); procedure FileExitItemClick (Sender: TObject); procedure FormResize (Sender: TObject); procedure ViewLargeItemClick (Sender: TObject); procedure ViewSmallItemClick (Sender: TObject); procedure ViewListItemClick (Sender: TObject); procedure ViewDetailsItemClick (Sender: TObject); procedure ViewRefreshItemClick (Sender: TObject); procedure CopyItemClick (Sender: TObject); procedure ToolsDisconnectItemClick (Sender: TObject); procedure FileNewItemClick (Sender: TObject); procedure DeleteItemClick (Sender: TObject); procedure PasteFromItemClick (Sender : TObject); procedure FilePopupPopup (Sender: TObject); procedure FileMenuClick (Sender: TObject); procedure FileDeleteItemClick (Sender: TObject); procedure FTPListItem (Sender: TObject; const Item: FTPDirItem); private p>
Root : TTreeNode; function CreateItem (const FileName, Attributes, Size, Date:
Variant): TListItem; procedure Disconnect; public function NodePath (Node: TTreeNode): String; end; p>
var p>
Myftp: TMyFtp; p>
UserName,
Pwd: String; p>
implementation p>
($ R *. DFM) p>
uses ShellAPI, UsrInfo; p>
function FixCase (Path: String): String; var p>
OrdValue: byte; begin if Length (Path) = 0 then exit; p>
OrdValue: = Ord (Path [1] ); if (OrdValue> = Ord ( 'a')) and (OrdValue 0 then begin if Size div 1024 0 then begin p>
SubItems.Add (IntToStr (Size div 1024 )); p>
SubItems [0]: = SubItems [0] + 'KB'; end else p>
SubItems.Add (Size); end else p>
SubItems.Add ('') ; if Attributes = '1 'then begin p>
SubItems.Add (' File Folder'); p>
ImageIndex: = 3; end else begin p>
Ext: = ExtractFileExt (FileName); p>
ShGetFileInfo (PChar ( 'c: *' + Ext), 0, SHFileInfo,
SizeOf (SHFileInfo), p>
SHGFI_SMALLICON or SHGFI_SYSICONINDEX or SHGFI_TYPENAME); if Length (SHFileInfo.szTypeName) = 0 then begin if Length (Ext)> 0 then begin p>
System.Delete ( Ext, 1, 1); p>
SubItems.Add (Ext + 'File'); end else p>
SubItems.Add ( 'File'); end else p> < p> SubItems.Add (SHFileInfo.szTypeName); p>
ImageIndex: = SHFileInfo.iIcon; end; p>
SubItems.Add (Date); end; end; p> < p> procedure TMyFtp.Disconnect; begin p>
FTP.Quit; p>
Application.ProcessMessages; end; p>
procedure TMyFtp.FormCreate (Sender: TObject); var p>
SHFileInfo: TSHFileInfo; begin with DirTree do begin p>
DirTree.Images: = SmallImages; p>
SmallImages.ResourceLoad (rtBitmap, 'IMAGES', clOlive); end; with FileList do begin p>
SmallImages: = TImageList.CreateSize (16,16); p>
SmallImages.ShareImages: = True; p>
SmallImages.Handle: = ShGetFileInfo ('*.*', 0, SHFileInfo, p>
SizeOf (SHFileInfo), SHGFI_SMALLICON or SHGFI_ICON or
SHGFI_SYSICONINDEX); p>
LargeImages: = TImageList.Create (nil); p>
LargeImages.ShareImages: = True; p>
LargeImages.Handle: = ShGetFileInfo ( '* .* ', 0, SHFileInfo, p>
SizeOf (SHFileInfo), SHGFI_LARGEICON or SHGFI_ICON or
SHGFI_SYSICONINDEX); end; end; p>
procedure TMyFtp.FTPBusy (Sender: TObject; isBusy: Wordbool); begin if isBusy then begin p>
Screen.Cursor: = crHourGlass; p >
FileList.Items.BeginUpdate; p>
FileList.Items.Clear; end else begin p>
Screen.Cursor: = crDefault; p>
FileList.Items . EndUpdate; end; end; p>
function TMyFtp.NodePath (Node: TTreeNode): String; begin if Node = Root then p>
Result: = '.' else p>
Result: = NodePath (Node.Parent) + '/' + Node.Text; end; p>
procedure TMyFtp.DirTreeChange (Sender: TObject; Node: TTreeNode); var p>
NP: String; begin if (FTP.State prcConnected) or FTP.Busy then exit; if Node nil then begin p>
NP: = NodePath (DirTree.Selected); p>
FTP.List (NP); p>
Label2.Caption: = Format ( 'Contents of:''% s /''',[ NP]); end; end; p>
procedure TMyFtp.RefreshBtnClick (Sender: TObject); begin p>
FTP.List (NodePath (DirTree.Selected)); end; p>
procedure TMyFtp.DirTreeChanging (Sender : TObject; Node: TTreeNode; var AllowChange: Boolean); begin p>
AllowChange: = not FTP.Busy; end; p>
procedure TMyFtp.FTPStateChanged (Sender: TObject; State: Smallint ); begin with FTP, Statusbar.Panels [0] do case State of prcConnecting: Text: = 'Connecting'; prcResolvingHost: Text: = 'Connecting'; prcHostResolved: Text: = 'Host resolved'; prcConnected: begin p >
Text: = 'Connected to:' + RemoteHost; p>
ConnectBtn.Hint: = 'Disconnect'; p>
FileNewItem.Enabled: = True; p> < p> ViewLargeItem.Enabled: = True; p>
ViewSmallItem.Enabled: = True; p>
ViewListItem.Enabled: = True; p>
ViewDetailsItem.Enabled: = True ; p>
ViewRefreshItem.Enabled: = True; p>
ToolsDisconnectItem.Enabled: = True; p>
LargeBtn.Enabled: = True; p>
SmallBtn.Enabled: = True; p>
ListBtn.Enabled: = True; p>
DetailsBtn.Enabled: = True; p>
RefreshBtn.Enabled: = True; end ; prcDisconnecting: Text: = 'Disconnecting'; prcDisconnected: begin p>
Text: = 'Disconnected'; p>
ConnectBtn.Hint: = 'Connect'; p>
DirTree.Items.Clear; p>
FileNewItem.Enabled: = False; p>
ViewLargeItem.Enabled: = False; p>
ViewSmallItem.Enabled: = False; p>
ViewListItem.Enabled: = False; p>
ViewDetailsItem.Enabled: = False; p>
ViewRefreshItem.Enabled: = False; p>
ToolsDisconnectItem.Enabled : = False; p>
LargeBtn.Enabled: = False; p>
SmallBtn.Enabled: = False; p>
ListBtn.Enabled: = False; p>
DetailsBtn.Enabled: = False; p>
RefreshBtn.Enabled: = False; end; end; end; p>
procedure TMyFtp.Open1Click (Sender: TObject); begin p>
FTP.Quit; p>
DirTree.Items.BeginUpdate; try p>
DirTree.Items.Clear; finally p>
DirTree.Items.EndUpdate; end; end; p>
procedure TMyFtp.FileExitItemClick (Sender: TObject); begin p>
Close; end; p>
procedure TMyFtp.FormResize (Sender: TObject); begin p>
Statusbar.Panels [0]. Width: = Width - 150; end; p>
procedure TMyFtp.ViewLargeItemClick (Sender: TObject); begin p>
FileList . ViewStyle: = vsIcon; end; p>
procedure TMyFtp.ViewSmallItemClick (Sender: TObject); begin p>
FileList.ViewStyle: = vsSmallIcon; end; p>
procedure TMyFtp.ViewListItemClick (Sender: TObject); begin p>
FileList.ViewStyle: = vsList; end; p>
procedure TMyFtp.ViewDetailsItemClick (Sender: TObject); begin p>
FileList.ViewStyle: = vsReport; end; p>
procedure TMyFtp.ViewRefreshItemClick (Sender: TObject); begin p>
DirTreeChange (nil, DirTree.Selected); end; p>
procedure TMyFtp.CopyItemClick (Sender: TObject); begin p>
SaveDialog1.FileName: = FileList.Selected.Caption; if SaveDialog1.Execute then p>
FTP.GetFile (NodePath ( DirTree.Selected) + '/' +
FileList.Selected.Caption, p>
SaveDialog1.FileName); end; p>
procedure TMyFtp.ToolsDisconnectItemClick (Sender: TObject); begin p>
DisConnect; end;
procedure TMyFtp.FileNewItemClick (Sender: TObject); var p>
DirName: String; begin if InputQuery ( 'Input Box', 'Prompt', DirName) then p>
FTP.CreateDir (NodePath (DirTree.Selected) + '/' + DirName); end; p>
procedure TMyFtp.DeleteItemClick (Sender: TObject); begin if ActiveControl = DirTree then p>
FTP.DeleteDir (NodePath (DirTree.Selected)); if ActiveControl = FileList then p>
FTP.DeleteFile (NodePath (DirTree.Selected) + '/' +
FileList.Selected.Caption); end; p>
procedure TMyFtp.PasteFromItemClick (Sender: TObject); begin if OpenDialog1.Execute then p>
FTP.PutFile (OpenDialog1.FileName, NodePath (DirTree . Selected)); end; p>
procedure TMyFtp.FilePopupPopup (Sender: TObject); begin p>
CopyItem.Enabled: = (ActiveControl = FileList) and (FileList.Selected nil); p>
PasteFromItem.Enabled: = (ActiveControl = DirTree) and
(DirTree.Selected nil); p>
DeleteItem.Enabled: = (ActiveControl = FileList) and
(FileList.Selected nil); p>
RenameItem.Enabled: = (ActiveControl = FileList) and
(FileList.Selected nil); end; p>
procedure TMyFtp.FileMenuClick (Sender: TObject); begin p>
FileCopyItem.Enabled: = (ActiveControl = FileList) and
(FileList.Selected nil); p>
FileDeleteItem.Enabled: = (ActiveControl = FileList) and
(FileList.Selected nil); p>
FileRenameItem.Enabled: = (ActiveControl = FileList) and
(FileList.Selected nil); end; p>
procedure TMyFtp.FileDeleteItemClick (Sender: TObject); begin if (DirTree.Selected nil) and (FileList.Selected nil) then p>
FTP . DeleteFile (FileList.Selected.Caption); end; p>
procedure TMyFtp.FTPListItem (Sender: TObject; const Item: FTPDirItem); var p>
Node: TTreeNode; begin p >
CreateItem (Item.FileName, Item.Attributes, Item.Size, Item.Date); if Item.Attributes = 1 then if DirTree.Selected nil then begin if DirTree.Selected nil then p>
Node: = DirTree.Selected.GetFirstChild else p>
Node: = nil; while Node nil do if AnsiCompareFileName (Node.Text, Item.FileName) = 0 then exit else p>
Node: = DirTree.Selected.GetNextChild (Node); if Node = nil then begin p>
Node: = DirTree.Items.AddChild (DirTree.Selected, p>
Item.FileName); p>
Node.ImageIndex: = Folder; p>
Node.SelectedIndex: = OpenFolder; end; end else p>
DirTree.Items.AddChild (Root, Item.FileName); end; p>
end. p>
Дз п № л ? ркозтфрCх; уАчх (и, хXюKхеюИф @ ьuу ('fфяьюМ ‡
1EF
№ p>
юЕьsхmу0хттиьшфайл nntp.pas p>
unit nntp; p>
interface p>
uses p>
Windows, Messages, SysUtils , Classes, Graphics, Controls, Forms,
Dialogs, p>
Menus, OleCtrls, StdCtrls, ComCtrls, ExtCtrls, Buttons, ActiveX, isp3; p>
const efListGroups = 0; efGetArticleHeaders = 1; efGetArticleNumbers = 2; efGetArticle = 3;
type p>
TNewsForm = class (TForm) p>
NNTP1: TNNTP; p>
MainMenu1: TMainMenu; p>
File1 : TMenuItem; p>
Exit1: TMenuItem; p>
N1: TMenuItem; p>
FileDisconnectItem: TMenuItem; p>
FileConnectItem: TMenuItem; p >
Panel1: TPanel; p>
Bevel1: TBevel; p>
StatusBar: TStatusBar; p>
SmallImages: TImageList; p>
Panel2: TPanel; p>
NewsGroups: TTreeView; p>
Bevel2: TBevel; p>
Panel3: TPanel; p>
Memo1: TMemo; p>
Panel5: TPanel; p>
Panel4: TPanel; p>
ConnectBtn: TSpeedButton; p>
RefreshBtn: TSpeedButton; p>
Bevel3: TBevel ; p>
MsgHeaders: TListBox; p>
Label1: TLabel; p>
Label2: TLabel; procedure FileConnectItemClick (Sender: TObject); procedure NNTP1ProtocolStateChanged (Sender: TObject;
ProtocolState: Smallint); procedure NNTP1StateChanged (Sender: TObject; State: Smallint); procedure Exit1Click (Sender: TObject); procedure MsgHeadersDblClick (Sender: TObject); procedure FormClose (Sender: TObject; var Action: TCloseAction ); procedure NewsGroupsChange (Sender: TObject; Node: TTreeNode); procedure RefreshBtnClick (Sender: TObject); procedure FileDisconnectItemClick (Sender: TObject); procedure NNTP1Banner (Sender: TObject; const Banner: WideString); procedure NNTP1DocOutput (Sender: TObject; const DocOutput:
DocOutput); procedure NNTP1Error (Sender: TObject; Number: Smallint; var Description: WideString; Scode: Integer; const Source, p>
HelpFile: WideString; HelpContext: Integer; var CancelDisplay: WordBool); procedure NNTP1SelectGroup ( Sender: TObject; const groupName: WideString; firstMessage, lastMessage, msgCount: Integer); private p>
EventFlag: Integer; function NodePath (Node: TTreeNode): String; public p>
Data: String; end; p>
var p>
NewsForm: TNewsForm; p>
Remainder: String; p>
Nodes: TStringList; p> < p> CurrentGroup: String; p>
GroupCount: Integer; p>
implementation p>
uses Connect; p>
($ R *. DFM)
(TParser) p>
type p>
TToken = (etEnd, etSymbol, etName, etLiteral); p>
TParser = class private p >
FFlags: Integer; p>
FText: string; p>
FSourcePtr: PChar; p>
FSourceLine: Integer; p>
FTokenPtr: PChar; p>
FTokenString: string; p>
FToken: TToken; procedure SkipBlanks; procedure NextToken; public constructor Create (const Text: string; Groups: Boolean); end; p>
const sfAllowSpaces = 1; p>
constructor TParser.Create (const Text: string; Groups: Boolean); begin p>
FText: = Text; p>
FSourceLine: = 1; p>
FSourcePtr: = PChar (Text); if Groups then p>
FFlags: = sfAllowSpaces else p>
FFlags: = 0; p >
NextToken; end; p>
procedure TParser.SkipBlanks; begin while True do begin case FSourcePtr ^ of p>
# 0: begin if FSourcePtr ^ = # 0 then Exit;
Continue; end; p>
# 10: p>
Inc (FSourceLine); p>
# 33 .. # 255: p>
Exit; end; p>
Inc (FSourcePtr); end; end; p>
procedure TParser.NextToken; var p>
P, TokenStart: PChar; begin p>
SkipBlanks; p>
FTokenString: =''; p>
P: = FSourcePtr; while (P ^ # 0) and (P ^ 0 then p >
SMTPStatus.SimpleText: = Format ( 'Sending data:% d of% d bytes
(% d %%)', p>
[Trunc (DocInput.BytesTransferred), Trunc (DocInput.BytesTotal), p>
Trunc (DocInput.BytesTransferred/DocInput.BytesTotal * 100)] ) else p>
SMTPStatus.SimpleText: = 'Sending ...'; icDocEnd: if SMTPError then p>
SMTPStatus.SimpleText: =' Transfer aborted 'else p>
SMTPStatus.SimpleText: = Format ( 'Mail sent to% s (% d bytesdata) ', [eTo.Text, p>
Trunc (DocInput.BytesTransferred)]); end; p>
SMTPStatus.Update; end; p>
(The Error event is called whenever an error occurs in the backgroundprocessing. In addition to providing an error code and brief description, you can alsoaccess the SMTP component's Errors property (of type icErrors, an OLE object) to getmore detailed information) procedure TMail.SMTP1Error (Sender: TObject; Number: Smallint; var Description: WideString; Scode: Integer; const Source, p>
HelpFile: WideString; HelpContext: Integer; var CancelDisplay:
WordBool); var p>
I: Integer; p>
ErrorStr: string; begin p>
SMTPError: = True; p>
CancelDisplay: = True ; p>
(Get extended error information) for I: = 1 to SMTP1.Errors.Count do p>
ErrorStr: = Format (# 13 '(% s)', [SMTP1. Errors.Item (I). Description ]); p>
(Display error code, short and long error description) p>
MessageDlg (Format ( '% d -% s% s', [Number, Description, Trim (ErrorStr)]),mtError, [mbOK], 0); end; p>
(Unlike POP, SMTP does not require a user account on the host machine,so no user authorization is necessary) procedure TMail.SMTPConnectBtnClick (Sender: TObject); begin if SMTP1.State = prcConnected then p>
SMTP1.Quit else if SMTP1.State = prcDisconnected then begin p>
SMTP1.RemoteHost: = eSMTPServer.Text; p>
SMTPError: = False; p>
SMTP1.Connect (NoParam, NoParam); end; end; p>
(Unlike SMTP, users must be authorized on the POP server. The componentdefines a special protocol state, popAuthorization, when it requestsauthorization. If authorization is successful, the protocol state changes topopTransaction and p>
POP commands can be issued. Note that server connection is independentof the authorization state.) procedure TMail.POP1ProtocolStateChanged (Sender: TObject; p>
ProtocolState: Smallint); begin case ProtocolState of popAuthorization: p>
POP1.Authenticate (POP1.UserID, POP1. Password); popTransaction: p>
ConnectStatus.SimpleText: = Format ( 'User% s authorized on server
% s ', [eUsername.Text, ePOPServer.Text]); end; end; p>
(This event is called every time the connection status of the POP serverchanges) procedure TMail.POP1StateChanged (Sender: TObject; State: Smallint); begin case State of prcConnecting: p>
ConnectStatus.SimpleText: = 'Connecting to POP server:
'+ POP1.RemoteHost +'...'; prcResolvingHost: p>
ConnectStatus.SimpleText: =' Resolving Host '; prcHostResolved: p>
ConnectStatus.SimpleText: =' Host Resolved '; prcConnected : begin p>
ConnectStatus.SimpleText: = 'Connected to POP server:
'+ POP1.RemoteHost; p>
POPConnectBtn.Caption: =' Disconnect '; end; prcDisconnecting: p>
ConnectStatus.SimpleText: =' Disconnecting from POP server:
'+ POP1.RemoteHost +'...'; prcDisconnected: begin p>
ConnectStatus.SimpleText: =' Disconnected from POP server:
'+ POP1.RemoteHost; p>
POPConnectBtn.Caption: =' Connect '; end; end; ePOPServer.Enabled: = not (State = prcConnected); eUsername.Enabled: = not (State = prcConnected); ePassword.Enabled: = not (State = prcConnected); end; p>
(The Error event is called whenever an error occurs in the backgroundprocessing. In addition to providing an error code and brief description, you can alsoaccess the POP component's Errors property (of type icErrors, an OLE object) to getmore detailed information) procedure TMail.POP1Error (Sender: TObject; Number: Smallint; var Description: WideString; Scode: Integer; const Source, p>
HelpFile: WideString; HelpContext: Integer; var CancelDisplay:
WordBool); var p>
I: Integer; p>
ErrorStr: string; begin p>
POPError: = True; p>
CancelDisplay: = True ; if POP1.ProtocolState = popAuthorization then p>
ConnectStatus.SimpleText: = 'Authorization error'; p>
(Get extended error information) for I: = 1 to POP1.Errors.Count do p>
ErrorStr: = Format (# 13 '(% s)', [POP1.Errors.Item (I). Description ]); p>
(Display error code, short and long error description) p>
MessageDlg (Format ( '% d -% s% s', [Number, Description, Trim (ErrorStr)]),mtError, [mbOK], 0); end; p>
(POP requires a valid user account on the host machine) procedure TMail.POPConnectBtnClick (Sender: TObject); begin if (POP1.State = prcConnected) and (POP1.ProtocolState =popTransaction) and not POP1.Busy then begin mReadMessage.Lines.Clear; p>
POP1.Quit; end else if POP1.State = prcDisconnected then begin p>
POP1.RemoteHost: = ePOPServer. Text; p>
POP1.UserID: = eUserName.Text; p>
POP1.Password: = ePassword.Text; p>
POP1.Connect (NoParam, NoParam); end; end; p>
(The DocOutput event is the just like the DocInput event in 'reverse'.
It is called each time the component's DocOutput state changes during retrieval of mail fromthe server. When the state = icDocData, you can call DocOutput.GetData to decode each datablock based on the MIME content type specified in the headers.) procedure TMail.POP1DocOutput (Sender: TObject; const DocOutput:
DocOutput); var p>
Buffer: WideString; p>
I: Integer; begin case DocOutput.State of icDocBegin: p>
POPStatus.SimpleText: = 'Initiating document transfer '; icDocHeaders: begin p>
POPStatus.SimpleText: =' Retrieving headers '; for I: = 1 to DocOutput.Headers.Count do mReadMessage.Lines.Add (DocOutput.Headers.Item (I). Name + ':' + p>
DocOutput.Headers.Item (I). Value); end; icDocData: begin p>
POPStatus.SimpleText: = Format ( 'Retrieving data -% d bytes' , p>
[Trunc (DocOutput.BytesTransferred )]); p>
Buffer: = DocOutput.DataString; mReadMessage.Text: = mReadMessage.Text + Buffer; end; icDocEnd: if POPError then p>
POPStatus.SimpleText: = 'Transfer aborted' else p>
POPStatus.SimpleText: = Format ( 'Retrieval complete (% d bytesdata )', p>
[Trunc (DocOutput.BytesTransferred)]); end; p>
POPStatus.Update; end; p>
(Retrieve message from the server) procedure TMail.udCurMessageClick (Sender: TObject; Button: TUDBtnType); begin if (POP1.State = prcConnected) and (POP1.ProtocolState =popTransaction) then begin p>
POPError: = False; mReadMessage.Lines.Clear; p>
POP1.RetrieveMessage (udCurMessage.Position); end; end; p>
( The RefreshMessageCount event is called whenever the
RefreshMessageCount method is called, and also when a connection to the POP server is first made) procedure TMail.POP1RefreshMessageCount (Sender: TObject; p>
Number: Integer); begin p>
FMessageCount: = Number; udCurMessage.Max: = Number; udCurMessage.Enabled: Number = 0; lMessageCount.Caption: = IntToStr (Number); if Number> 0 then begin udCurMessage.Min: = 1; udCurMessage.Position: = 1; p >
POP1.RetrieveMessage (udCurMessage.Position); end; end; p>
end. p>
Z p>
. p>
ф p>
х
Mqе ... ° в: зозZјз < p>
ил »ц" | я 7 я'Пцpпу лd p>
hл | япBIщQє? ЕE K-файл webbrows.dpr p>
program Webbrows; p>
uses p>
Forms, main in 'Main.pas' (MainForm), p >
SMTP in 'Smtp.pas', (Mail) p>
FTP in 'ftp.pas', (MyFtp) p>
NNTP in 'nntp.pas', (NewsForm ) p>
CHAT in 'chat.pas'; (ChatForm) p>
($ R *. RES) p>
begin p>
Application. Initialize; p>
Application.CreateForm (TMainForm, MainForm); p>
Application.CreateForm (TDocSourceFrm, DocSourceFrm); p>
Application.run; end. p >
Додаток 1. Оригінальний текст моделі корпоративної мережі p>
uses crt, dos, graph; p>
CONST VertexQuantity = 7; p>
DelayInDomain = 1000; p>
DelaySendToRouter = 1000; p>
DelayRouterReceive = 1000; p>
AdjacencyMatrix: array [1 .. VertexQuantity, 1 .. VertexQuantity] of byte = ( p>
(0,1 , 0,1,0,0,0), p>
(1,0,1,0,1,0,1), p>
(0,1,0,1 , 0,0,0), p>
(1,0,1,0,1,0,0), p>
(0,1,0,1,0,1 , 0), p>
(0,0,0,0,1,0,1), p>
(0,1,0,0,0,1,0)) ; p>
TYPE TAddr = record (address format) router: byte; domain: byte; comp: byte; p>
END; p>
TYPE TBatch = record (batch format) from: TAddr; to_: TAddr; data: string; path: array [1 .. 20] of byte; (path is chain of router numbers) p>
END; p>
TYPE TComp = object (terminal) addr: TAddr; (adress) mem: TBatch; (memory) p>
Procedure Send2Router (batch: TBatch); (send batch) p>
Procedure Send ( batch: TBatch); (send batch into domain) p>
Procedure Receive (batch: TBatch; byRouter: boolean); (receive batch) p>
END; p>
TYPE TRouter = object num: byte; x, y: integer; memory: Tbatch; state: boolean; (active or inactive) p>
Procedure Receive (routerNum: byte; batch: TBatch); p>
Procedure Send2Comp (batch: TBatch); p>
Procedure CalcMinPath (sender, target: byte); p>
Procedure Send2NextRouter (batch: TBatch; currentRouter: byte); p >
END; p>
VAR computers: array [1 .. 38] of TComp; (all computers in the globalnet) routers: array [1 .. 7] of TRouter; (all routers in the global net) p>
OptimalPath: array [1 .. 49] of byte; (1 -> [1,2 , 3,4,5]) p>
OptPathPtr: byte; p>
type TMark = record delta: integer; prevPtr: byte; end; type vertex = record mark: TMark; marked: boolean; end; p>
AdjacencyRec = record link: byte; weight: integer; end; p>
VAR AMatr: array [1 .. 7,1 .. 7] of AdjacencyRec; vertexArr : array [1 .. 7] of vertex; p>
PROCEDURE HiddenCursor; assembler; asm mov ah, 01 mov ch, 20 mov cl, 18 int 10h end; p>
PROCEDURE NormalCursor; assembler; asm mov ah, 01 mov ch, 9 mov cl, 10 int 10h end; p>
Procedure Push (num: byte); p>
Begin p>
OptimalPath [OptPathPtr 1]: = num; inc (OptPathPtr); p>
End; p>
Procedure Pop; p>
Begin p>
OptimalPath [ OptPathPtr]: = 0; dec (OptPathPtr); p>
End; p>
Procedure ShowGraphics (second: boolean); p>
Var grDr, grMode: integer; i : integer; p>
Begin grDr: = vga; grMode: = 2; p>
InitGraph (grDr, grMode, 'd: langtpbgi'); p>
SetTextStyle ( DefaultFont, HorizDir, 2); SetColor (lightRed); p>
OutTextXY (10,20, 'Arrangement scheme of routers'); p>
SetColor (white); Rectangle (5,15,480 , 40); p>
Rectangle (5,48,480,70); SetTextStyle (DefaultFont, HorizDir, 1); setcolor (lightgreen); p>
OutTextXY (10,55, 'Main address: Router.Domain.Computer (for ex.,
4.2.4) '); setcolor (white); setFillStyle (7, lightblue); floodfill (5,5, white); p>
setlinestyle (0,0,3); rectangle (0,0, getmaxX-20, getmaxY-20); setFillStyle (9, lightgray); floodfill (getmaxX, getmaxY, white); setlinestyle (0,0, NormWidth); p>
SetFillStyle (1, red); p>
{------------------- router circles ----------------------- ) p>
Circle (routers [1]. x, routers [1]. y, 10); FloodFill (routers [1]. x, routers [1]. y, white); p>
Circle (routers [2]. x, routers [2]. y, 10); FloodFill (routers [2]. x, routers [2]. y, white); p>
Circle (routers [3]. x, routers [3]. y, 10); FloodFill (routers [3]. x, routers [3]. y, white); p>
Circle (routers [4]. x, routers [4]. y, 10); FloodFill (routers [4]. x, routers [4]. y, white); p>
Circle (routers [5]. x, routers [5]. y, 10); FloodFill (routers [5]. x, routers [5]. y, white); p>
Circle (routers [6]. x, routers [6]. y, 10); FloodFill (routers [6]. x, routers [6]. y, white); p>
Circle (routers [7]. x, routers [7]. y, 10); FloodFill (routers [7]. x, routers [7]. y, white); p>
SetFillStyle (1, yellow); p>
SetColor (red );{------------------- router lines -------------------------
) p>
Line (routers [1]. x, routers [1]. y-10, routers [2]. x-2, routers [2]. y +10); p> < p> Line (routers [1]. x, routers [1]. y 10, routers [4]. x-10, routers [4]. y-6); p>
Line (routers [ 3]. x, routers [3]. y-10, routers [2]. x 2, routers [2]. y +10); p>
Line (routers [3]. x, routers [3]. y 10, routers [4]. x, routers [4]. y-10); p>
Line (routers [2]. x 4, routers [2]. y + 10, routers [5]. x-2, routers [5]. y-10); p>
Line (routers [2]. x 10, routers [2]. y, routers [7] . x-10, routers [7]. y); p>
Line (routers [5]. x 2, routers [5]. y-10, routers [6]. x, routers [6 ]. y +10); p>
Line (routers [6]. x, routers [6]. y-10, routers [7]. x, routers [7]. y +10);
Line (routers [4]. x 10, routers [4]. y, routers [5]. x-10, routers [5]. y); p>
(domains ) {------------- domain 1.1 --------------------------------- -
) p>
SetTextStyle (DefaultFont, HorizDir, 1); SetColor (white); p>
Rectangle (routers [1]. x-50, routers [1]. y-50, routers [1]. x-30, routers [1]. y-
20); p>
FloodFill (routers [1]. X-48, routers [1]. Y-48, white); p>
Circle (20, routers [1]. Y -30,8); FloodFill (20, routers [1]. y-30, white); p>
Circle (40, routers [1]. y-30, 8); FloodFill (40, routers [1]. y-30, white); p>
Circle (60, routers [1]. y-30, 8); FloodFill (60, routers [1]. y-30, white); p>
SetColor (white); p>
Line (routers [1]. x-5, routers [1]. y-10, routers [1]. x-20, routers [ 1]. y-30); p>
Line (routers [1]. x-20, routers [1]. y-30, routers [1]. x-110, routers [1]. y -
30); p>
{------------- domain 1.2 ------------------------ ----------} p>
Rectangle (routers [1]. x-30, routers [1]. y 80, routers [1]. x-
5, routers [1]. Y +92); p>
FloodFill (routers [1]. X-28, routers [1]. Y 82, white); p>
Line (routers [1]. x-2, routers [1]. y 10, routers [1]. x-20, routers [1]. y +80); p>
Circle (routers [1 ]. x-48, routers [1]. y +62,9); p>
FloodFill (routers [1]. x-48, routers [1]. y 62, white); p>
Line (routers [1]. x-28, routers [1]. y 82, routers [1]. x-52, routers [1]. y +62); p>
Circle (routers [1]. x 10, routers [1]. y +62,8); p>
FloodFill (routers [1]. x 10, routers [1]. y 62 , white); p>
Line (routers [1]. x-5, routers [1]. y 82, routers [1]. x 10, routers [1]. y +62); p>
Circle (routers [1]. x-48, routers [1]. y +92,8); p>
FloodFill (routers [1]. x-48, routers [ 1]. y 92, white); p>
Line (routers [1]. x-28, routers [1]. y 90, routers [1]. x-48, routers [1] . y +92); p>
Circle (routers [1]. x-43, routers [1]. y +115,8); p>
FloodFill (routers [1]. x-43, routers [1]. y 115, white); p>
Line (routers [1]. x-23, routers [1]. y 90, routers [1]. x -
48, routers [1]. Y +115); p>
Circle (routers [1]. X-18, routers [1]. Y +115,8); p>
FloodFill (routers [1]. x-18, routers [1]. y 115, white); p>
Line (routers [1]. x-18, routers [1]. y 90, routers [1]. x-
18, routers [1]. Y +115); p>
Circle (routers [1]. X 13, routers [1]. Y +113,8); p>
FloodFill (routers [1]. x 13, routers [1]. y 113, white); p>
Line (routers [1]. x-5, routers [1]. y 92, routers [1]. x 13, routers [1]. y +113); p>
{------------- domain 2.1 --------- -------------------------} p>
Rectangle (routers [2]. x-
25, routers [2]. Y 70, routers [2]. X 16, routers [2]. Y +79); p>
FloodFill (routers [2]. X-24, routers [ 2]. y 72, white); p>
Line (routers [2]. x, routers [2]. y 10, routers [2]. x-5, routers [2]. y +70); p>
Circle (routers [2]. x-24, routers [2]. y +100,8); p>
FloodFill (routers [2]. x - 24, routers [2]. y 100, white); p>
Line (routers [2]. x, routers [2]. y 72, routers [2]. x-24, routers [ 2]. y +100); p>
{------------- domain 2.2 ------------------- ---------------} p>
Rectangle (routers [2]. x-80, routers [2]. y 10, routers [2]. x -
60, routers [2]. Y +37); p>
FloodFill (routers [2]. X-78, routers [2]. Y 12, white); p>
Line (routers [2]. x-10, routers [2]. y, routers [2]. x-70, routers [2]. y +20); p>
Circle (routers [2]. x-110, routers [2]. y +20,8); p>
FloodFill (routers [2]. x-110, routers [2]. y 20, white); p>
Circle (routers [2]. x-140, routers [2]. y +20,8); p>
FloodFill (routers [2]. x-140, routers [2]. y 20, white); p>
Line (routers [2]. x-70, routers [2]. y 20, routers [2]. x-
150, routers [2]. Y +20); p>
{------------- domain 3.1 --------------- -------------------} p>
Rectangle (routers [3]. x-45, routers [3]. y-47, routers [3 ]. x-25, routers [3]. y-
20); p>
FloodFill (routers [3]. X-43, routers [3]. Y-45, white); p>
Circle (routers [3]. X-60 , routers [3]. y-37, 8); p>
FloodFill (routers [3]. x-60, routers [3]. y-37, white); p>
Circle (routers [3]. x-80, routers [3]. y-37, 8); p>
FloodFill (routers [3]. x-80, routers [3]. y-37, white); p>
Line (routers [3]. x-7, routers [3]. y-8, routers [3]. x-35, routers [3]. y-37);
Line (routers [3]. x-35, routers [3]. y-37, routers [3]. x-90, routers [3]. y-37); p> < p> {------------- domain 4.1 -------------------------------- --} p>
Rectangle (routers [4]. x-39, routers [4]. y-82, routers [4]. x-13, routers [4]. y-
70); p>
FloodFill (routers [4]. X-37, routers [4]. Y-81, white); p>
Line (routers [4]. X-4 , routers [4]. y-10, routers [4]. x-25, routers [4]. y-70); p>
Circle (routers [4]. x-40, routers [4 ]. y-105, 8); p>
FloodFill (routers [4]. x-40, routers [4]. y-105, white); p>
Line (routers [ 4]. x-25, routers [4]. y-75, routers [4]. x-40, routers [4]. y-
105); p>
Circle (routers [4]. X-60, routers [4]. Y-70, 8); p>
FloodFill (routers [4]. X-60 , routers [4]. y-70, white); p>
Line (routers [4]. x-25, routers [4]. y-75, routers [4]. x-60, routers [4]. y-70); p>
Circle (routers [4]. x-40, routers [4]. y-50, 8); p>
FloodFill (routers [ 4]. x-40, routers [4]. y-50, white); p>
Line (routers [4]. x-25, routers [4]. y-75, routers [4] . x-40, routers [4]. y-50); p>
{------------- domain 4.2 ------------ ----------------------} p>
Rectangle (routers [4]. x 25, routers [4]. y-35, routers [4]. x 45, routers [4]. y-
5); p>
FloodFill (routers [4]. X 27, routers [4]. Y-33, white); p>
Circle (routers [4]. X 57 , routers [4]. y-25, 8); p>
FloodFill (routers [4]. x 57, routers [4]. y-25, white); p>
Circle (routers [4]. x 77, routers [4]. y-25, 8); p>
FloodFill (routers [4]. x 77, routers [4]. y-25, white); p>
Circle (routers [4]. x 97, routers [4]. y-25, 8); p>
FloodFill (routers [4]. x 97 , routers [4]. y-25, white); p>
Circle (routers [4]. x 117, routers [4]. y-25, 8); p>
FloodFill (routers [4]. x 117, routers [4]. y-25, white); p>
Line (routers [4]. x 9, routers [4]. y-7, routers [4]. x 20, routers [4]. y-25); p>
Line (routers [4]. x 20, routers [4]. y-25, routers [4] . x 127, routers [4]. y-
25); p>
{------------- domain 5.1 ------------------------ ----------} p>
Rectangle (routers [5]. x-30, routers [5]. y-130, routers [5]. x-
10, routers [5]. Y-100); p>
FloodFill (routers [5]. X-25, routers [5]. Y-128, white); p>
Line (routers [5]. x, routers [5]. y-10, routers [5]. x-20, routers [5]. y-120); p>
Circle (routers [5]. x-48, routers [5]. y-90, 8); p>
FloodFill (routers [5]. x-48, routers [5]. y-120 +30, white); p>
Line (routers [5]. x-20, routers [5]. y-120, routers [5]. x-48, routers [5]. y-
90); p>
Circle (routers [5]. X-50, routers [5]. Y-120, 8); p>
FloodFill (routers [5]. X-50 , routers [5]. y-120, white); p>
Line (routers [5]. x-20, routers [5]. y-120, routers [5]. x-50, routers [5]. y-
120); p>
Circle (routers [5]. X-25, routers [5]. Y-150, 8); p>
FloodFill (routers [5]. X-25 , routers [5]. y-150, white); p>
Line (routers [5]. x-20, routers [5]. y-120, routers [5]. x-25, routers [5]. y-
150); p>
Circle (routers [5]. X 2, routers [5]. Y-150, 8); p>
FloodFill (routers [5]. X 2 , routers [5]. y-150, white); p>
Line (routers [5]. x-20, routers [5]. y-120, routers [5]. x 2, routers [5]. y-
150); p>
{------------- domain 6.1 ------------------------ ----------} p>
Rectangle (routers [6]. x-30, routers [6]. y-10, routers [6]. x-
14, routers [6]. Y +14); p>
FloodFill (routers [6]. X-28, routers [6]. Y-8, white); p>
Circle (routers [6]. x-42, routers [6]. y, 8); p>
FloodFill (routers [6]. x-42, routers [6]. y, white); p>
Circle (routers [6]. x-62, routers [6]. y, 8); p>
FloodFill (routers [6]. x-62, routers [6]. y , white); p>
Circle (routers [6]. x-82, routers [6]. y, 8); p>
FloodFill (routers [6]. x-82, routers [6]. y, white); p>
Line (routers [6]. x-10, routers [6]. y, routers [6]. x-92, routers [6]. y ); p>
{------------- domain 7.1 ------------------------- ---------} p>
Rectangle (routers [7]. x-10, routers [7]. y-50, routers [7]. x 10, routers [7] . y-
25); p>
FloodFill (routers [7]. X-8, routers [7]. Y-48, white); p>
Line (routers [7]. X, routers [7]. y-10, routers [7]. x, routers [7]. y-50); p>
Circle (routers [7]. x-35, routers [7]. y - 20,8); p>
FloodFill (routers [7]. x-35, routers [7]. y-20, white); p>
Line (routers [7]. x , routers [7]. y-50, routers [7]. x-35, routers [7]. y-20); p>
Circle (routers [7]. x-35, routers [7 ]. y-60, 8); p>
FloodFill (routers [7]. x-35, routers [7]. y-60, white); p>
Circle (routers [ 7]. x 15, routers [7]. y-70, 8); p>
FloodFill (routers [7]. x 15, routers [7]. y-70, white);
Line (routers [7]. x, routers [7]. y-50, routers [7]. x 15, routers [7]. y-70); p>
Line (routers [7]. x, routers [7]. y-50, routers [7]. x-35, routers [7]. y-60); p>
SetColor (cyan);
OuttextXY (18, routers [1]. y-32, '4'); p>
OuttextXY (38, routers [1]. y-32, '3 '); OuttextXY (58, routers [1]. y-32, '2'); p>
OutTextXY (routers [1]. x-48, routers [1]. y-48, 'FS');
OuttextXY (78, routers [1]. y-32, '1'); p>
OutTextXY (routers [1]. x 8, routers [1]. y 60 , '1'); p>
OutTextXY (routers [1]. x-50, routers [1]. y 60, '6'); p>
OutTextXY (routers [1 ]. x-50, routers [1]. y 89, '5'); p>
OutTextXY (routers [1]. x-45, routers [1]. y 113, '4 ' ); p>
OutTextXY (routers [1]. x-20, routers [1]. y 112, '3'); p>
OutTextXY (routers [1]. x - 28, routers [1]. y 82, 'hub'); p>
OutTextXY (routers [1]. x 11, routers [1]. y 111, '2'); p>
OutTextXY (routers [2]. x-24, routers [2]. y 72, 'modem'); p>
OutTextXY (routers [2]. x-26, routers [ 2]. y 98, '1'); p>
OutTextXY (routers [2]. x-78, routers [2]. y 12, 'FS'); p>
OutTextXY (routers [2]. x-73, routers [2]. y 24, '1'); p>
OutTextXY (routers [2]. x-112, routers [2]. y 18, '2'); p>
OutTextXY (routers [2]. x-142, routers [2]. y 18, '3'); p>
OutTextXY (routers [3]. x-42, routers [3]. y-45, 'FS'); p>
OutTextXY (routers [3]. x-38, routers [3]. y-30,' 1'); p>
OutTextXY (routers [3]. x-62, routers [3]. y-40, '2'); p>
OutTextXY (routers [3]. x-82, routers [3]. y-40, '3'); p>
OutTextXY (routers [4]. x-37, routers [4]. y-80, 'hub'); p>
OutTextXY (routers [4]. x-42, routers [4]. y-107, '1'); p>
OutTextXY (routers [4]. x-62, routers [4]. y-73, '2'); p>
OutTextXY (routers [4]. x-42, routers [4]. y-53, '3'); p>
OutTextXY (routers [4]. x 28, routers [4]. y-33, 'FS'); p>
OutTextXY (routers [4]. x 33, routers [4] . y-20, '1'); p>
OutTextXY (routers [4]. x 55, routers [4]. y-27, '2'); p>
OutTextXY (routers [4]. x 75, routers [4]. y-27, '3'); p>
OutTextXY (routers [4]. x 95, routers [4]. y-27 , '4'); p>
OutTextXY (routers [4]. x 115, routers [4]. y-27, '5'); p>
OutTextXY (routers [5 ]. x-27, routers [5]. y-127, 'FS'); p>
OutTextXY (routers [5]. x-21, routers [5]. y-110, '1' ); p>
OutTextXY (routers [5]. x-51, routers [5]. y-92, '2'); p>
OutTextXY (routers [5]. x - 51, routers [5]. y-122, '3'); p>
OutTextXY (routers [5]. x-27, routers [5]. y-152, '4'); p>
OutTextXY (routers [5]. x, routers [5]. y-152, '5'); p>
OutTextXY (routers [6]. x-29, routers [6] . y-8, 'FS'); p>
OutTextXY (routers [6]. x-25, routers [6]. y 4, '1'); p>
OutTextXY (routers [6]. x-44, routers [6]. y-2, '2'); p>
OutTextXY (routers [6]. x-64, routers [6]. y-2 , '3'); p>
OutTextXY (routers [6]. x-84, routers [6]. y-2, '4'); p>
OutTextXY (routers [7 ]. x-7, routers [7]. y-48, 'FS'); p>
OutTextXY (routers [7]. x-2, routers [7]. y-35, '1' ); p>
OutTextXY (routers [7]. x-37, routers [7]. y-22, '2'); p>
OutTextXY (routers [7]. x - 37, routers [7]. y-62, '3'); p>
OutTextXY (routers [7]. x 12, routers [7]. y-72, '4'); p>
SetColor (white); p>
OutTextXY (10,230, 'Domain 1.1'); OutTextXY (10,338, 'Domain 1.2'); p>
OutTextXY (200,220,' Domain 2.1 '); OutTextXY (110,150,' Domain 2.2'); p>
OutTextXY (210,240, 'Domain 3.1'); p>
OutTextXY (170,320,' Domain 4.1 '); OutTextXY ( 330,370, 'Domain 4.2'); p>
OutTextXY (430,250,' Domain 5.1'); p>
OutTextXY (450,175, 'Domain 6.1'); p>
( ------------- router numbers -------------------------) p>
SetColor ( black); p>
OutTextXY (routers [1]. x-2, routers [1]. y-2, '1'); p>
OutTextXY (routers [2]. x -2, routers [2]. y-2, '2'); p>
OutTextXY (routers [3]. x-2, routers [3]. y-2, '3 ');
OutTextXY (routers [4]. x-2, routers [4]. y-2, '4'); p>
OutTextXY (routers [5]. x-2, routers [5]. y-2, '5'); p>
OutTextXY (routers [6]. x-2, routers [6]. y-2, '6'); p> < p> OutTextXY (routers [7]. x-2, routers [7]. y-2, '7 '); if second then begin setlinestyle (0,0,3); setcolor ((white) green); for i : = 1 to OptPathPtr-2 do p>
Line (routers [OptimalPath [i]]. x, routers [OptimalPath [i]]. y, routers [OptimalPath [i +1]]. x, routers [OptimalPath [i +1]]. y); while not keypressed do for i: = 1 to 63 do SetRGBPalette (green, 0, i, 0); end; if not second then while not keypressed do for i: = 1 to 63 do SetRGBPalette (red, i, 0,0); p>
End; p>
Procedure ShowTime (x, y: integer); p>
VAR h, m, s, hund: Word; p>
Function LeadingZero (w: Word): String; var s: String; begin p>
Str (w: 0, s); if Length ( s) = 1 then s: = '0 '+ s; p>
LeadingZero: = s; end; p>
Begin p>
GetTime (h, m, s , hund); TextColor (Green); GotoXY (x, y); Write (LeadingZero (h ),':', p>
LeadingZero (m ),':', LeadingZero (s), '. ', LeadingZero (hund )); p>
End; p>
Function Dist (x1, y1, x2, y2: longint): longint; var temp: longint; p> < p> Begin temp: = sqr (x2-x1) + sqr (y2-y1); temp: = trunc ((sqrt (temp ))); p>
Dist: = temp; p> < p> End; p>
{----------------- objects implementation part -----------------) p>
{--------------- Computer procedures ---------------) p>
Procedure TComp . Send2Router (batch: TBatch); (send batch to it's router) p>
VAR i: byte; tmpFrom: TAddr; p>
Begin p>
Delay (DelaySendToRouter) ; tmpFrom: = batch.from; i: = batch.from.router; routers [i]. memory: = batch; (router receive data from his domain'scomputer) showtime (wherex, wherey); writeln ( '>', tmpFrom.router ,'.', tmpFrom.domain ,'.', tmpFrom.comp, p>
'says: I send data', ' "', batch.data ,'"',' for
', batch.to_.router ,'.', batch.to_.domain ,'.', batch.to_.comp,' to router ', i); for i: = 1 to 38 do if p> < p> (computers [i]. addr.router = tmpFrom.router) AND
(computers [i]. addr.domain = tmpFrom.domain) p>
AND (computers [i]. addr.comp = tmpFrom.comp) then break; computers [i]. mem.data: = ' '; (clear memory) p>
End; p>
Procedure TComp.Send (batch: TBatch); (into domain) p>
VAR i: byte; tmpTo, tmpFrom: TAddr; p>
Begin p>
Delay (DelayInDomain); tmpTo: = batch.to_; tmpFrom: = batch.from; for i: = 1 to 38 do if p >
(computers [i]. addr.router = tmpTo.router) AND
(computers [i]. addr.domain = tmpTo.domain) p>
AND (computers [i]. addr.comp = tmpTo.comp) then break; computers [i]. mem: = batch; ( Send!) showtime (wherex, wherey); writeln ( '>', tmpFrom.router ,'.', tmpFrom.domain ,'.', tmpFrom.comp, p>
'says: I send data' ,'"', batch.data ,'"',' to
', batch.to_.router ,'.', batch.to_.domain ,'.', batch.to_.comp); for i: = 1 to 38 do if p>
(computers [i] . addr.router = tmpFrom.router) AND
(computers [i]. addr.domain = tmpFrom.domain) p>
AND (computers [i]. addr.comp = tmpFrom.comp) then break; computers [i]. mem.data: = ' '; (clear memory) p>
End; p>
Procedure TComp.Receive (batch: TBatch; byRouter: boolean); (computer receivedata from his domain's router) p>
VAR tmpTo: TAddr; p>
Begin p>
Delay (DelayInDomain); tmpTo: = batch.to_; showtime (wherex, wherey ); write ( '>', tmpTo.router ,'.', tmpTo.domain ,'.', tmpTo.comp, p>
'says: I receive data','"', batch.data ,'"',' from
', batch.from.router ,'.', batch.from.domain ,'.', batch.from.comp); if byRouter then writeln (' by router ', tmpTo.router); p>
End; p>
{------------- Router procedures -------------------) p>
Procedure TRouter.CalcMinPath (sender, target: byte); p>
VAR i, j: byte; k: byte; p>
AllVertexMarked: boolean; p>
Begin p>
{----------------------- Initialization ---------------- ----------} for i: = 1 to 7 do for j: = 1 to 7 do if AdjacencyMatrix [i, j] = 1 then AMatr [i, j]. link: = 1 else AMatr [i, j]. link: = 0; for i: = 1 to 7 do for j: = 1 to 7 do AMatr [i, j]. weight: = 0; p>
Randomize; p>
For j: = 2 to7 do for i: = 1 to j-1 do AMatr [i, j]. weight: = random (50); for i: = 1 to 7 do vertexArr [i]. marked: = false; p>
{-------------------------- Make marks --------- --------------------} p>
{---- mark last vertex ----} p>
vertexArr [ target]. mark.delta: = 0; vertexArr [target]. mark.prevPtr: = target; vertexArr [target]. marked: = true; p>
AllVertexMarked: = false; p>
While not AllVertexMarked do BEGIN p>
For j: = 1 to 7 do p>
For i: = 1 to 7 do begin (j ---> i) if (AMatr [i , j]. link0) AND (vertexArr [j]. marked) p>
AND (not vertexArr [i]. marked) then begin if not ((vertexArr [j]. marked) AND (j = sender )) then begin p>
vertexArr [i]. mark.delta: = vertexArr [j]. mark.delta + AMatr [j, i]. weight; vertexArr [i]. mark.prevPtr: = j ; vertexArr [i]. marked: = true; end; end; p>
End; p>
AllVertexMarked: = true; for i: = 1 to 7 do if vertexArr [i]. marked = false then
AllVertexMarked: = false; p>
END; (While not AllVertexMarked) p>
{----------------------- --- Main test -----------------------------} for i: = 1 to 49 do OptimalPath [i]: = 0 ; p>
For i: = 1 to 7 do vertexArr [i]. marked: = false; vertexArr [sender]. marked: = true; p>
For j: = 1 to 7 do p>
For i: = 1 to 7 do begin {---- deltaA-deltaB> d (AB) then changemark) p>
() if (vertexArr [j]. marked) AND (not (vertexArr [i]. marked)) then begin vertexArr [i]. marked: = true; for k: = 1 to 7 do if (AMatr [k, j]. link = 1) then begin p>
if vertexArr [j]. mark.delta -vertexArr [k]. mark.delta> AMatr [k, j]. weight then begin vertexArr [j]. mark.prevPtr: = k; vertexArr [j]. mark.delta: = vertexArr [k]. mark.delta + AMatr [k, j]. weight; vertexArr [k]. marked: = true; end (else vertexArr [k]. marked: = true); end; end; p>
() end; (if adjacency vertex found) push (sender); p>
k: = vertexArr [sender]. mark.prevPtr; push (k); p>
While ktarget do begin push (vertexArr [k] . mark.PrevPtr); k: = vertexArr [k]. mark.PrevPtr; p>
End; p>
End; p>
Procedure TRouter.Send2NextRouter (batch: TBatch; currentRouter: byte); p>
Begin p>
Delay (DelayRouterReceive + AMatr [currentRouter, OptimalPath [OptPathPtr]]. link); p>
showtime (wherex, wherey); writeln ( '> router', currentRouter, p>
'says: I send data','"', batch.data ,'"',' from
', batch.from.router ,'.', batch.from.domain ,'.', batch.from.comp,' to router ', OptimalPath [OptPathPtr]); routers [OptimalPath [OptPathPtr]]. memory: = batch; inc (OptPathPtr); routers [currentRouter]. memory.data :=''{ clear memory) p>
End; p>
Procedure TRouter.receive (routerNum: byte; batch: TBatch); p>
Begin p>
Delay (DelayRouterReceive); showtime (wherex, wherey); writeln ( '> router', routerNum, p>
'says: I receive data','"', batch.data ,'"',' from
', batch.from.router ,'.', batch.from.domain ,'.', batch.from.comp); p>
End; p>
Procedure TRouter.send2comp ( batch: TBatch); p>
VAR i: byte; tmpTo, tmpFrom: TAddr; p>
Begin p>
Delay (DelayInDomain); tmpTo: = batch.to_; tmpFrom: = batch.from; for i: = 1 to 38 do if p>
(computers [i]. addr.router = tmpTo.router) AND
(computers [i]. addr.domain = tmpTo.domain) p>
AND (computers [i]. addr.comp = tmpTo.comp) then break; computers [i]. mem: = batch; ( Send!) showtime (wherex, wherey); writeln ( '> router', tmpTo.router, p>
'says: I send data','"', batch.data ,'"',' to
', batch.to_.router ,'.', batch.to_.domain ,'.', batch.to_.comp); routers [tmpTo.router]. memory.data :='';{ clear memory) p>
End; p>
Procedure Initialization; p>
VAR i, j: integer; p>
Begin p>
(--- ---------- INITIALIZATION PART -------------} p>
FOR i: = 1 to 7 do begin (routers initialization) routers [i] . num: = i; routers [i]. state: = true; routers [i]. memory.data :=''; for j: = 1 to 20 do routers [i]. memory.path [j]: = 0; p>
END; routers [1]. x: = 120; routers [1]. y: = 300; routers [2]. x: = 250; routers [2]. y: = 100 ; routers [3]. x: = 320; routers [3]. y: = 300; routers [4]. x: = 300; routers [4]. y: = 420; routers [5]. x: = 500 ; routers [5]. y: = 420; routers [6]. x: = 540; routers [6]. y: = 200; routers [7]. x: = 550; routers [7]. y: = 100 ; p>
FOR i: = 1 to 38 do computers [i]. mem.data :='';{ computersinitialization) j: = 1; for i: = 1 to 4 do begin (router 1, domain 1) computers [i]. addr.router: = 1; computers [i]. addr.domain: = 1; computers [i ]. addr.comp: = j; inc (j); end; j: = 1; for i: = 5 to 10 do begin (router 1, domain 2) computers [i]. addr.router: = 1; computers [i]. addr.domain: = 2; computers [i]. addr.comp: = j; inc (j); end; (router 2, domain 1) p>
computers [11]. addr . router: = 2; computers [11]. addr.domain: = 1; computers [11]. addr
. comp: = 1; j: = 1; for i: = 12 to 14 do begin (router 2, domain 2) computers [i]. addr.router: = 2; computers [i]. Addr.domain: = 2; computers [i]. Addr.comp: = j; inc (j); end; j: = 1; for i: = 15 to 17 do begin ( router 3, domain 1) computers [i]. addr.router: = 3; computers [i]. addr.domain: = 1; computers [i]. addr.comp: = j; inc (j); end; j : = 1; for i: = 18 to 20 do begin (router 4, domain 1) computers [i]. addr.router: = 4; computers [i]. addr.domain: = 1; computers [i]. addr . comp: = j; inc (j); end; j: = 1; for i: = 21 to 25 do begin (router 4, domain 2) computers [i]. addr.router: = 4; computers [i] . addr.domain: = 2; computers [i]. addr.comp: = j; inc (j); end; j: = 1; for i: = 26 to 30 do begin (router 5, domain 1) computers [ i]. addr.router: = 5; computers [i]. addr.domain: = 1; computers [i]. addr.comp: = j; inc (j); end; j: = 1; for i: = 31 to 34 do begin (router 6, domain 1) computers [i]. addr.router: = 6; computers [i]. addr.domain: = 1; computers [i]. addr.comp: = j; inc ( j); end; j: = 1; for i: = 35 to 38 do begin (router 7, domain 1) computers [i]. addr.router: = 7; computers [i]. addr.domain: = 1; computers [i]. addr.comp: = j; inc (j); end; p>
{------------- END OF INITIALIZATION PART ------ -------} p>
End; p>
Procedure Error (ErrorNum: byte); p>
Begin textcolor (lightred); writeln ( 'Error! '); case ErrorNum of p>
1: writeln (' One (or two) of above addresses are not exist'); p>
2: writeln ( 'FROM and TO are same' ); end; readln; halt; p>
End; p>
VAR tmpStr: string; tmpFrom: TAddr; tmpTo: TAddr; tmpData: string; i, j: integer; tmpX, tmpY : integer; p>
FromNum, ToNum: byte; (index FROM and TO computers in array) p>
BEGIN {------------- MAIN PROGRAM -- --------------} p>
Initialization; p>
ShowGraphics (false); readln; CloseGraph; p>
ClrScr; TextColor (LightGreen); write ( 'Global Network Emulation'); ShowTime (70,1); writeln; p>
{------------- ADDRESS AND DATA REQUEST --- ------------} p>
Write ( 'Enter FROM address (XXX):'); readln (tmpStr); (FROM request -
-----} p>
Val (tmpStr [1], tmpFrom.router, i); Val (tmpStr [3], tmpFrom.domain, i); p>
Val ( tmpStr [5], tmpFrom.comp, i); (target request -------------------------
----} p>
Write ( 'Enter TO address (XXX):'); readln (tmpStr); p>
Val (tmpStr [1], tmpTo.router, i) ; Val (tmpStr [3], tmpTo.domain, i); p>
Val (tmpStr [5], tmpTo.comp, i); p>
Write ( 'Enter string-type DATA: '); readln (tmpData); p>
{------------- SEARCH' FROM 'TERMINAL -------------- -----} for i: = 1 to 38 do if p>
(computers [i]. addr.router = tmpFrom.router) AND
(computers [i]. addr.domain = tmpFrom.domain) p>
AND (computers [i]. addr.comp = tmpFrom.comp) then FromNum: = i; p>
( ------------- SEARCH 'TO' TERMINAL ----------------------} for i: = 1 to 38 do if p>
(computers [i]. addr.router = tmpTo.router) AND
(computers [i]. addr.domain = tmpTo.domain) p>
AND (computers [i]. addr.comp = tmpTo.comp) then ToNum: = i; if (FromNum = 0) OR ( ToNum = 0) then Error (1); if FromNum = ToNum then Error (2); (computer cannot send batch to itself) p>
{------------- FILL 'ADDRESS' FIELDS ---