Académique Documents
Professionnel Documents
Culture Documents
Table of Contents
1.
2. 3.
INTRODUCTION 01 DRIVER INSTALLATION AND SETTINGS... 04 EXPERIMENT 1 PC TO PC COMMUNICATION.... 11 A. B. SERIAL COMMUNICATION PARALLEL COMMUNICATION
4.
5.
6.
7.
8.
9.
10.
11.
EXPERIMENT 9
IMPLEMENTATION AND STUDY OF CSMA-CA PROTOCOL... 95
12.
13. EXPERIMENT 11. IMPLEMENTATION OF DISTANCE VECTOR ROUTING ALGORITHM . 105 14. EXPERIMENT 12.
IMPLEMENTATION OF LINK STATE ROUTING ALGORITHM. 111 APPENDIX. 117
15.
- II -
INTRODUCTION
Rapid advances in computer & communication technologies have resulted in the increasing merger of these two fields. The lines have blurred among computing,
switching & digital transmission equipment; and the same digital techniques are
timely collection, processing & dissemination of information, have led to the development of integrated systems that transmit & process all types of data. These integrated systems are broadly divided as follows - DATA COMMUNICATION dealing with transmission, transmission media, signal decoding, interfacing, data link control & multiplexing - NETWORKING deals with the technology & architecture of communication network - COMMUNICATION PROTOCOLS which covers the architecture as well
as analysis of individual protocols at various layers depending on the
hardware & software Network laboratory is designed & developed considering the curriculum offered by
Anna University. Trainers offered under network laboratory are designed for students at all level to study and understand all the concepts of data communication, data transfer using serial and parallel ports, Ethernet and wireless LAN with complete protocol understanding and actual hands on with hardware &
analyzer software & N-SIM Network simulation software. The DCT-03: Data communication trainer is a unique trainer kit for the development of exercises and theoretical-experimental courses to understand the basic concept and working of modes and protocols in serial and parallel communication. The trainer kit consists of functional blocks for serial and parallel communication system. The trainer kit is highly innovative from a technological as well as an educational point of view. The trainer kit is used as basic unit to examine all the peculiar operating standards of serial and parallel communication system. The only external equipments required are two Computers with serial and parallel communication ports and an Oscilloscope. Utmost care has been laid in the design and quality control of all circuits, to ensure the repeatability of the results of the experiments.
-1-
Data communication is a term referred when the sender and receiver are digital devices, which communicate with each other by means of binary information. The
objective of this trainer kit is to clear the various aspects of the data
communications which comprise of The information source or sender. The medium for carrying information. The information receiver. The communication protocols, which ensure proper transfer of data. With an increasing demand in information exchange the field of data communication technique is emerging as the only solution, to satisfy the various
needs of todays communication sector and to achieve very high bandwidth along with highest accuracy. The communication media is shifting from analog signal
transfer towards digital communication. With PC becoming the biggest storage devices in digital form, it becomes the
main source and destination for information exchange. With rapid growth in both
Now the digital data is used for data, voice and image transmission.
Depending upon the application the communication link can be of point to point communication between two devices or a multipoint communication between at
least 3 devices and data transfer can be serial or in parallel form. LTS-01 Local area network / wireless local area network trainer system is
designed to help students understand the basic concepts, modes of operation and protocols involved in networking. The trainer has integrated hardware flow control on panel board for better understanding of different types of LAN topologies involved in networking. The trainer system is provided with windows-based userfriendly software with analysis of protocols, different layers, network and measurement of error rate and throughput. Students can easily do connections in different topologies and can learn actual data transfer either through hardware or through simulated network concept. Facility is provided into system software to introduce errors into packets being sent and analyze the effect of error on different protocols and hence find the effect on through put graph as well. Trainer is supported with help into software window for better understanding of system and
-2-
Transmitter port protocol & network analysis can be done after communication is
over between server and clients. Throughput v/s Packet size graph can be plotted for which at least two file transfers should be carried out. This plot can be printed
device.
L-SIM LAN Protocol Simulator & Analyzer Software is designed to teach the basic concepts, topologies & various protocols involved in networking. The software is provided with analysis of protocols, different layers, network and measurement of error rate and throughput. Facility is provided to introduce errors into packets being sent and analyze the effect of error on different protocols and hence find the effect on throughput graph as well. Software is supported with neat operating
instruction manual and online help. N-SIM Network simulation software is developed to provide basic understanding and implementation of various advanced concepts in networking. The software provides an opportunity to understand network fundamentals through animations & simulations. The simulation provides for network experimentation with various LAN and WAN protocols, network devices, routers, encryption, decryption, file transfer, error insertion and analysis of error rate and throughput etc. This software covers Ethernet LAN, wireless LAN and router. All networking theory is explained using simulation and animation. SYSTEM REQUIREMENTS: PC: Pentium or higher One LAN card onboard or on PCI slot with 10/100Mbps speed. 128MB RAM 500MB free space on Hard drive CD ROM drive Serial port, LPT port & USB port installed on system Operating System: Windows 2000 or higher
-3-
NOTE: If HYPER TERMINAL is not available at the above path then follow the procedure ahead to add hyper terminal link. Go to START MENU SETTINGS control panel Add/Remove programs windows setup double click on communications select Hyper terminal, click OK and follow the procedure below. 2. A new Window will open, where in you Double Click on HYPERTERM, Two Windows will open, one at the background and another (small window) with title Connection Description which will be Active.
3.
Enter the name in the box by which you would like to store your connection, for e.g. (PC2PC), and Click OK. Also you could select the Icon provided below. The background window title will change to the name provided by you.
4.
Then specify connect using: by selecting Direct to COM1 or port where your cable is connected and then click on OK.
-4-
(NOTE: Please check the Port you have selected and the Ports you are connecting). 5. Now Window with Title COM 1 Properties will appear where Port Setting should be done as shown above and click on OK. BITS PER SECOND Data Bits Parity None Stop Bits Flow Control UP TO 115200 8 1 Xon / Xoff
(NOTE: For Bits Per Second setting you could select them for different speeds from 110bps to115200 bps).
6. After the above settings you click ok. the background window will become
7. 8.
9.
active. Click on file, save as, and save it in the directory, which you want. Perform the same procedure (from 1 to 8.) on another pc.
To start communicating between the two PCs click on the transfer menu and again click on send file. A window will be prompted having title send
-5-
10.
11.
Select browse for the file, which you would like to send to the pc connected, select the file and click on open, the file name and address will be displayed in the small window. Then select the protocol, (optional use protocols are x modem, y modem and 1k xmodem, etc.) To receive the file on the pc click on the transfer menu and again click on receive file. a window will be prompted having title receive file with location at which you want to store the received file and receiving protocol.
12.
Select browse for the location where you would like to store the received
file, select the folder and click ok, the folder name and address will be displayed in the small window. Protocol to be selected should be same as
-6-
14.
After file is transferred both the windows in the (transmitting & receiving
PCs) will close. Check for the received file in the folder where the file is
15.
stored. You can select any pc as transmitter or receiver & follow the above procedure to transfer the file.
NOTE: To change the bits per second rate (baud rate) go to properties in the hyper terminal window, click on file menu, properties and configure, in the bits per second select other rates. From 2400 to 115200 bps. You will observe that the rate at which the file is transferred will vary with the selected baud rate. Also you can observe and check that by removing fiber from detector packet increment and file transfer stops. Also ensure that at the left corner of the hyper terminal window connected time must be on, if disconnected label is there go to call option and press call. NOTE: If HyperTerminal is not installed in your computer then, on PC Go to My Computer Control Panel, Add Remove Programs, Windows Setup, Communication, Check Hyper Terminal and Click OK
-7-
WIRELESS USB ADAPTER DRIVER INSTALLATION PROCEDURE FOR INSTALLING WIRELESS USB ADAPTER DRIVER: 1. Insert the driver CD for Wireless USB Adapter. It auto runs and will open the following screen.
2.
3.
-8-
4.
Setup will install in the by default folder. To install to this by default folder, click Next. To install to a different folder, click Browse and select another folder.
5.
Setup will add program icons to the Program Folder listed. Type a new folder name, or select one from the existing folders list. Click Next to continue.
-9-
6.
The Install Shield Wizard has successfully installed the software. Before using the program, the computer must be restarted.
- 10 -
EXPERIMENT 1
PC TO PC COMMUNICATION
- 11 -
PC1
L SERIACA BLE
PC2
COMP ORT
- 12 -
TD 2 OFF CT S2 RTS2 SF 1 ON
EXPERIMENT 1:
OBJECTIVE: To study Serial communication using RS 232C and Parallel Communication using 8 bit parallel cable. EQUIPMENTS: DCT-03. 9 Pin D connector Cables 2 Nos. 25 Pin D connector Cables 2 Nos. Computers PC - 2 nos. Connecting Chords. Power Supply. PROCEDURE: SERIAL COMMUNICATION: 1. Connect the power supply with proper polarity to the kit DCT-03 and while connecting, ensure that it is off. 2. Keep all switch fault switches in off position. 3. Refer to the fig. and carry out the following connections and settings. 4. Connect 9 pin D connector cable between one computer com port and CN3 connector on DCT-03 kit and second 9 pin D connector cable between another computer com port and CN4 connector on DCT-03 kit. 5. Connect the TD1 post to RD2 post. 6. Connect the RD1 post to TD2 post. 7. Keep the switch setting of SW4 towards ON position as shown in figure. 8. Switch ON the power supply and both the computers. 9. Run DCT-03 software and select Serial Communication Software link on both PCs.
Select your computer operating system, this will provide link to hyper terminal software. Refer Hyperlink settings. Once the connection to hyperlink is established you can type in one of the computers window and can see typed text on another computers window. To do file transfer select a file transfer protocol using hyper link on both PCs.
- 13 -
13.
Put the flow control on XON / XOFF & repeat the procedure of file transfer for the X-MODEM, Y-MODEM, Z-MODEM, KERMIT protocol.
14.
Select the receiving file save location and the same protocol as selected in
transmitter.
15.
Click on file transfer button you will see progress of file transfer.
- 14 -
16. 17.
18. 19.
You will see progress of file receiving in the receiver. Variations in LED indications of respective ports can be observed while file is being transmitted from one computer to another.
For observation of ASCII equivalent of keyboard data transmitted connect
corresponding fault switch button to ON position & observe the different effects on the output. The faults are normally used one at a time. 1. Put switch 1 of SF1 in Switch Fault section to ON position. This will open pin no. 5 of U8A [CD4082], hence the clock Q3 will be absent at the i/p of U8. Pin no. 5 will always remain high and the count will change, resulting change in latched ASCII data. It will show only a part of the 8 bit data, or will not accept new data, during character transfer on Hyper window.
- 15 -
PC1
T LPPOR T
PC
- 16 LL EL PAPORT RA CABL E
DATA POR T
D6 D7
DATA PO RT
LL EL PAPORT RA CABL E
PC sw 6
PR N
FSTU
DY OFD A T
PARALLEL COMMUNICATION: 1.
2. 3. 4.
5. 6. 7.
Carry out the following connections and settings as shown in the diagram. Keep all switch fault switches in off position. Keep switch SW6 in PC mode. Connect LPT/parallel port of one PC to connector CN1 on left hand side on DCT-03 kit using 25-25 pin D type cable. Similarly connect LPT/parallel port of another PC to connector CN2 on right hand side on DCT-03 kit using 25-25 pin D type cable. Keep the switch settings for SW1, SW2 & SW3 in ON position as shown. Switch ON the power supply. Run DCT software and select Parallel Communication Software link on both PCs.
8.
9.
10.
Clicking on Port Setting will show you three ports (i.e. LPT1, LPT2, LPT3), select the port from the user machine through which the data transfer has to occur. For example Clicking on LPT1 will set the LPT1 as the active port on the machine for the data transfer. Please ensure that the selected ports are in bi-directional mode, this can be checked from the BIOS settings of the computer. Clicking on Protocols will show you three protocols namely Stop and Wait
Protocol, Go Back N Protocol and Selective Repeat protocol. Select Same
protocol on both PC. Screen similar to one given below will appear.
- 17 -
11. 12.
Select one PC in transmit mode and another PC in receive mode. Select the file to be sent from the transmitter computer, the screen shown
below will appear at transmitter side, with details of file selected number of
13.
14.
packets formed using 128 byte per packet size. Inter packet delay can be varied from 5 ms to 100 ms.
Window size for Go back N & Selective Repeat protocols can be selected
15.
16.
- 18 -
17. 18.
On the remote PC click on receive file button. Status of file transfer will be indicated on screen with different colour coding
depending on the status of packet whether it is sent & acknowledged, sent
Packet No.
21. Any positive acknowledge received is displayed as ACK(0) and any negative acknowledge is displayed as NACK(0) along with their packet
sequence in brackets.
22. 23. 24. 25. Once the packet has been acknowledged and signal shown the next
successful at transmitter.
26.
At the receiver a selection window will popup to indicate location for the
27.
28. 29.
Verify the received file with transmitted file, this shows end of file transfer with success.
The receiving packets can be discarded or killed by clicking the Discard
button.
Any acknowledge that is transmitted back can be also made to lost by just clicking Lost button. Thus the Transmitter side will not receive any
acknowledge.
30. 31. The third button NACK/LOST can be clicked to discard and to lose any
- 20 -
EXPERIMENT 2
STUDY OF STOP & WAIT PROTOCOL
- 21 -
PC1
LPT POR T
STATUS POR T
T LPPOR T
PC
DATA POR T
D6 D7
DATA POR T
PC sw 6
PRN
FS TU
DY OFD A T
EXPERIMENT 2:
OBJECTIVE: To study Stop & Wait protocol using parallel port & LAN port interface. A. USING PARALLEL PORT:
EQUIPMENTS: DCT-03 trainer kit. 25 Pin D connector Cables 2 Nos. 2 Computers with win-2K / XP. Connecting Chords. Power Supply. PROCEDURE: 1.
2. 3. 4.
5. 6. 7. 8.
9.
10.
Carry out the following connections and settings as shown in the diagram. Keep all switch fault switches in off position. Keep switch SW6 in PC mode. Connect LPT/parallel port of one PC to connector CN1 on left hand side on DCT-03 kit using 25-25 pin D type cable. Similarly connect LPT/parallel port of another PC to connector CN2 on right hand side on DCT-03 kit using 25-25 pin D type cable. Keep the switch settings for SW1, SW2 & SW3 in ON position as shown. Switch ON the power supply. Run DCT software and select Parallel Communication Software link on both PCs. Clicking on Port Setting will show you three ports (i.e. LPT1, LPT2, LPT3), select the port from the user machine through which the data transfer has to occur. For example Clicking on LPT1 will set the LPT1 as the active port on the machine for the data transfer. Please ensure that the selected ports are in bi-directional mode, this can be checked from the BIOS settings of the computer. Clicking on Protocols will show you three protocols namely Stop and Wait
Protocol, Go Back N Protocol and Selective Repeat protocol. Select Stop
11.
and Wait protocol on both PC. Select one PC in transmit mode and another PC in receive mode.
- 23 -
12.
Select the file to be sent from the transmitter computer, the screen shown
below will appear at transmitter side, with details of file selected number of
13.
packets formed using 128 byte per packet size. Inter packet delay can be varied from 5 ms to 100 ms.
14. 15.
Packets to be sent are shown with blue colour. Click on Transmit file button.
- 24 -
16. 17.
On the remote PC click on receive file button. Status of file transfer will be indicated on screen with different colour coding
depending on the status of packet whether it is sent & acknowledged, sent
Packet No.
- 25 -
20.
sequence in brackets.
21. 22. 23. Once the packet has been acknowledged and signal shown the next
- 26 -
- 27 -
SERVER
CLIENT-1
CLIENT-2
PORT-1
PORT-2
PORT-3
SWITCH
PORT-6
PORT-5
PORT-4
CLIENT-5
CLIENT-4
CLIENT-3
- 28 -
24.
25. 26. 27. 28.
Once the file transfer gets complete you will be prompted by file transfer successful at transmitter.
At the receiver a selection window will popup to indicate location for the
with success.
The receiving packets can be discarded or killed by clicking the Discard
button.
Any acknowledge that is transmitted back can be also made to lost by just clicking Lost button. Thus the Transmitter side will not receive any
acknowledge.
29. The third button NACK/LOST can be clicked to discard and to lose any
EQUIPMENTS: LTS-01 trainer kit. 2 Computers with win-2K / XP and Ethernet port available on them RJ-45 to RJ-45 LAN connecting cables. L-SIM LAN protocol analyzer and simulator software PROCEDURE: 1.
2. 3. 4. 5. 6.
7.
8.
Connect 2 computer LAN ports using RJ-45 to RJ-45 LAN connecting cables provided with the system to LTS-01 star topology ports. Switch on the LTS-01 & Computers. Run L-SIM software on all the computers, one should be server and others should be clients. On the server computer select type of network as LAN. On the server computer select the topology as STAR, select protocol as Stop & Wait click on create network button. Remote computer details will appear on the computers connected in network, server will be able to see all clients and all clients will be able to see only server. Select the computer to whom data file is to be transferred, from the load button, previously stored/selected file information can be loaded or you can select any file, which is to be transmitted. File size will appear in the software window, select the packet size, inter packet delay and click OK.
- 29 -
9.
10. 11.
Same details of file will appear on remote computer to which file is to be transmitted. Click on file transfer button to transfer file.
- 30 -
During file transfer process you can insert errors into data packets being transmitted through software window.
See the effect of Bad packet error, Packet negative acknowledgment error
- 31 -
14.
Select BAD PACKET error and click on Generate button in the transmitter window when say 7th packet is in the transmission state.
15.
You will see that 7th packet in the receiver window will be marked as bad
packet.
- 32 -
16.
17.
- 33 -
18.
Select ACK LOST error and click on Generate button in the transmitter window when say 23rd packet is in the transmission state.
19.
You will see that 23rd packet in the receiver window will be marked as
unacknowledged.
- 34 -
20.
21. Retransmitted
- 35 -
22.
user.
23. 24.
25.
Status of packets received when auto error is selected. File transfer from one computer to another will take place.
Multiple file transfer between various server-client combinations should be performed to observe throughput v/s packet size graph on transmitter
computer.
26. Close file transfer window and click on protocol analyzer and Network
27. 28.
analyzer buttons on transmitter computer to view details of the log created. Under Network analyzer window click on Graph analyzer button. Calculate throughput and click on Plot graph button.
- 36 -
29. 30.
Detailed graph of throughput v/s packet size for the total file transfer activity wil appear on graph window. This plot can be printed by clicking on print button.
Graph for Stop & Wait protocol without any packet errors
Graph for Stop & Wait protocol with one ACK lost packet error
- 37 -
- 38 -
EXPERIMENT 3
STUDY OF GO BACK N PROTOCOL
- 39 -
PC1
LPT POR T
STATUS POR T
T LPPOR T
PC
DATA POR T
D6 D7
DATA POR T
PC sw 6
PRN
FS TU
DY OFD A T
EXPERIMENT 3:
OBJECTIVE: To study Go Back N protocol using parallel port & LAN port interface. A. USING PARALLEL PORT:
EQUIPMENTS: DCT-03 trainer kit. 25 Pin D connector Cables 2 Nos. 2 Computers with win-2K / XP. Connecting Chords. Power Supply. PROCEDURE: 1.
2. 3. 4.
5. 6. 7. 8.
9.
10.
Carry out the following connections and settings as shown in the diagram. Keep all switch fault switches in off position. Keep switch SW6 in PC mode. Connect LPT/parallel port of one PC to connector CN1 on left hand side on DCT-03 kit using 25-25 pin D type cable. Similarly connect LPT/parallel port of another PC to connector CN2 on right hand side on DCT-03 kit using 25-25 pin D type cable. Keep the switch settings for SW1, SW2 & SW3 in ON position as shown. Switch ON the power supply. Run DCT software and select Parallel Communication Software link on both PCs. Clicking on Port Setting will show you three ports (i.e. LPT1, LPT2, LPT3), select the port from the user machine through which the data transfer has to occur. For example Clicking on LPT1 will set the LPT1 as the active port on the machine for the data transfer. Please ensure that the selected ports are in bi-directional mode, this can be checked from the BIOS settings of the computer. Clicking on Protocols will show you three protocols namely Stop and Wait
Protocol, Go Back N Protocol and Selective Repeat protocol. Select Go
11.
12.
Back N protocol on both PC. Select one PC in transmit mode and another PC in receive mode.
Select the file to be sent from the transmitter computer, the screen will shown details of file selected number of packets formed using 128 byte per
packet size. Inter packet delay can be varied from 5 ms to 100 ms. Window size can be selected from 3, 5, 7. Packets to be sent are shown with blue colour. Click on Transmit file button. On the remote PC click on receive file button.
Status of file transfer will be indicated on screen with different colour coding depending on the status of packet whether it is sent & acknowledged, sent
- 41 -
19.
After the user has selected the file. The PC shows the No of Packets and
Size of the file in the boxes on the top. The Packets with their packet
20.
Once the transfer starts and the client computer acknowledges the packets it sends the signal back to the transmitting PC. Any acknowledge positive or negative with their packet sequence is displayed below the Current
Packet No.
- 42 -
21.
sequence in brackets.
Once the packet has been acknowledged and signal shown the next
window is retransmitted.
On the right hand top shows frame info. The frame info consists of different
- 43 -
SERVER
CLIENT-1
CLIENT-2
PORT-1
PORT-2
PORT-3
SWITCH
PORT-6
PORT-5
PORT-4
CLIENT-5
CLIENT-4
CLIENT-3
- 44 -
26.
27. 28. 29. 30.
Once the file transfer gets complete you will be prompted by file transfer successful at transmitter.
At the receiver a selection window will popup to indicate location for the
with success.
The receiving packets can be discarded or killed by clicking the Discard
button.
Any acknowledge that is transmitted back can be also made to lost by just clicking Lost button. Thus the Transmitter side will not receive any
acknowledge.
31. The third button NACK/LOST can be clicked to discard and to lose any
EQUIPMENTS: LTS-01 trainer kit. 2 Computers with win-2K / XP and Ethernet port available on them. RJ-45 to RJ-45 LAN connecting cables. L-SIM LAN protocol analyzer and simulator software PROCEDURE: 1.
2. 3. 4. 5. 6.
7.
8.
Connect 3 or more computer LAN ports using RJ-45 to RJ-45 LAN connecting cables provided with the system to LTS-01 star topology ports. Switch on the LTS-01 & Computers. Run L-SIM software on all the computers, one should be server and others should be clients. On the server computer select type of network as LAN. On the server computer select the topology as STAR, select protocol as Go Back N click on create network button. Remote computer details will appear on the computers connected in network, server will be able to see all clients and all clients will be able to see only server. Select the computer to whom data file is to be transferred, from the load button, previously stored/selected file information can be loaded or you can select any file, which is to be transmitted. File size will appear in the software window, select the packet size, inter packet delay, window size and click OK.
9.
10. 11.
Same details of file will appear on remote computer to which file is to be transmitted. Click on file transfer button to transfer file.
- 46 -
Transmission started screen in transmitter clearly show window size of 3 with 3 packets are transmitted at a time
During file transfer process you can insert errors into data packets being transmitted through software window.
See the effect of Bad packet error, Packet negative acknowledgment error or auto errors on file transfer; observe carefully which packet/packets are
transmitted.
- 47 -
14.
Select BAD PACKET error and click on Generate button in the transmitter window when say 15th packet is in the transmission state.
15.
You will see that 15th packet in the receiver window will be marked as bad
packet.
- 48 -
16.
17. Retransmitted 15th, 16th & 17th packets will be received correctly this time, receiver will discard 16th & 17th packets and only 15th packet is accepted.
- 49 -
18.
Select ACK LOST error and click on Generate button in the transmitter window when say 21st packet is in the transmission state.
19.
You will see that 21st packet in the receiver window will be marked as
unacknowledged.
- 50 -
20.
21.
Retransmitted 21st, 22nd & 23rd packets will be received and discarded by receiver as they were received correctly earlier.
- 51 -
22.
user.
23. 24.
25.
Status of packets received when auto error is selected. File transfer from one computer to another will take place.
Multiple file transfer between various server-client combinations should be performed to observe throughput v/s packet size graph on transmitter
computer.
26. Close file transfer window and click on protocol analyzer and Network
27. 28.
analyzer buttons on transmitter computer to view details of the log created. Under Network analyzer window click on Graph analyzer button. Calculate throughput and click on Plot graph button.
- 52 -
29.
Detailed graph of throughput v/s packet size for the total file transfer activity will appear on graph window.
Graph for Go Back N protocol without any packet errors 30. This plot can be printed by clicking on print button.
- 53 -
- 54 -
EXPERIMENT 4
STUDY OF SELECTIVE REPEAT PROTOCOL
- 55 -
PC1
LPT POR T
STATUS POR T
T LPPOR T
PC
DATA POR T
D6 D7
DATA POR T
PC sw 6
PRN
FS TU
DY OFD A T
EXPERIMENT 4:
OBJECTIVE: To study Selective Repeat protocol using parallel port & LAN port interface. A. USING PARALLEL PORT:
EQUIPMENTS: DCT-03 trainer kit. 25 Pin D connector Cables 2 Nos. 2 Computers with win-2K / XP. Connecting Chords. Power Supply. PROCEDURE: 1.
2. 3. 4.
5. 6. 7. 8.
9.
10.
Carry out the following connections and settings as shown in the diagram. Keep all switch fault switches in off position. Keep switch SW6 in PC mode. Connect LPT/parallel port of one PC to connector CN1 on left hand side on DCT-03 kit using 25-25 pin D type cable. Similarly connect LPT/parallel port of another PC to connector CN2 on right hand side on DCT-03 kit using 25-25 pin D type cable. Keep the switch settings for SW1, SW2 & SW3 in ON position as shown. Switch ON the power supply. Run DCT software and select Parallel Communication Software link on both PCs. Clicking on Port Setting will show you three ports (i.e. LPT1, LPT2, LPT3), select the port from the user machine through which the data transfer has to occur. For example Clicking on LPT1 will set the LPT1 as the active port on the machine for the data transfer. Please ensure that the selected ports are in bi-directional mode, this can be checked from the BIOS settings of the computer. Clicking on Protocols will show you three protocols namely Stop and Wait
Protocol, Go Back N Protocol and Selective Repeat protocol. Select
11.
12.
Selective Repeat protocol on both PC. Select one PC in transmit mode and another PC in receive mode.
Select the file to be sent from the transmitter computer, the screen will show with details of file selected number of packets formed using 128 byte
per packet size. Inter packet delay can be varied from 5 ms to 100 ms. Window size can be selected from 3, 5, 7. Packets to be sent are shown with blue colour. Click on Transmit file button. On the remote PC click on receive file button.
Status of file transfer will be indicated on screen with different colour coding depending on the status of packet whether it is sent & acknowledged, sent
- 57 -
19.
After the user has selected the file. The PC shows the No of Packets and
Size of the file in the boxes on the top. The Packets with their packet
20.
Once the transfer starts and the client computer acknowledges the packets it sends the signal back to the transmitting PC. Any acknowledge positive or negative with their packet sequence is displayed below the Current
Packet No.
21.
Any positive acknowledge received is displayed as ACK(0) and any negative acknowledge is displayed as NACK(0) along with their packet
sequence in brackets.
- 58 -
22.
gets retransmitted.
23. 24. 25. 26. 27. 28. 29. 30. Once the packet has been acknowledged and signal shown the next
successful at transmitter.
At the receiver a selection window will popup to indicate location for the
with success.
The receiving packets can be discarded or killed by clicking the Discard
button.
Any acknowledge that is transmitted back can be also made to lost by just clicking Lost button. Thus the Transmitter side will not receive any
acknowledge.
31. The third button NACK/LOST can be clicked to discard and to lose any
- 59 -
SERVER
CLIENT-1
CLIENT-2
PORT-1
PORT-2
PORT-3
SWITCH
PORT-6
PORT-5
PORT-4
CLIENT-5
CLIENT-4
CLIENT-3
- 60 -
B.
EQUIPMENTS: LTS-01 trainer kit. 2 Computers with win-2K / XP and Ethernet port available on them. RJ-45 to RJ-45 LAN connecting cables. L-SIM LAN protocol analyzer and simulator software PROCEDURE: 1.
2. 3. 4. 5. 6.
7.
8.
Connect 3 or more computer LAN ports using RJ-45 to RJ-45 LAN connecting cables provided with the system to LTS-01 star topology ports. Switch on the LTS-01 & Computers. Run L-SIM software on all the computers, one should be server and others should be clients. On the server computer select type of network as LAN. On the server computer select the topology as STAR, select protocol as Selective Repeat click on create network button. Remote computer details will appear on the computers connected in network, server will be able to see all clients and all clients will be able to see only server. Select the computer to whom data file is to be transferred, from the load button, previously stored/selected file information can be loaded or you can select any file, which is to be transmitted. File size will appear in the software window, select the packet size, inter packet delay, window size and click OK.
9.
- 61 -
10. 11.
Same details of file will appear on remote computer to which file is to be transmitted. Click on file transfer button to transfer file.
Transmission started screen in transmitter clearly show window size of 3 with 3 packets are transmitted at a time
- 62 -
During file transfer process you can insert errors into data packets being transmitted through software window.
See the effect of Bad packet error, Packet negative acknowledgment error or auto errors on file transfer; observe carefully which packet/packets are
transmitted.
14.
Select BAD PACKET error and click on Generate button in the transmitter
- 63 -
15.
You will see that 13th packet in the receiver window will be marked as bad packet.
16.
- 64 -
17. Retransmitted
18.
Select ACK LOST error and click on Generate button in the transmitter window when say 26th packet is in the transmission state.
- 65 -
19.
You will see that 26th packet in the receiver window will be marked as unacknowledged.
20.
- 66 -
21. Retransmitted 26th packet will be received and discarded by receiver as it was received correctly earlier.
22.
user.
- 67 -
Status of packets received when auto error is selected. File transfer from one computer to another will take place. Multiple file transfer between various server-client combinations should be
performed to observe throughput v/s packet size graph on transmitter
computer.
26. Close file transfer window and click on protocol analyzer and Network
analyzer buttons on transmitter computer to view details of the log created. Under Network analyzer window click on Graph analyzer button. Calculate throughput and click on Plot graph button. Detailed graph of throughput v/s packet size for the total file transfer activity will appear on graph window.
Graph for Selective Repeat protocol without any packet errors 30. This plot can be printed by clicking on print button.
- 68 -
EXPERIMENT 5
STUDY OF SOCKET PROCESSING
- 69 -
SERVER
CLIENT
PORT-1
PORT-2
PORT-3
SWITCH
PORT-6
PORT-5
PORT-4
- 70 -
EXPERIMENT 5:
OBJECTIVE: Study of socket processing. EQUIPMENTS: LTS-01 trainer kit 2 Computers with win-2K / XP and Visual C++ installed and Ethernet port available on them RJ-45 to RJ-45 LAN connecting cables PROCEDURE: 1. Connect 2 computer LAN ports using RJ-45 to RJ-45 LAN connecting cables provided with the system to LTS-01 star topology ports. 2. Switch on the LTS-01 & Computers. 3. Run VC++ editor on both the computers. 4. Create dialog based application, for Server on any of the PC in VC++ 5. Create dialog based application, for Client on other PC in VC++ 6. TCP Test Server.exe, TCP Test Client.exe, server.h, server.cpp, client.h & client.cpp files will be stored in the directory program files LSIM SampleApplication.zip. 7. After extracting the said zip files all these files can be used for socket programming. 8. Copy the server.h & server.cpp files in server workspace on first PC. 9. Copy the client.h & client.cpp files in Client workspace on second computer. 10. server.h file contain following functions: CreateSocket (int portNumber); ListenSocket(); SendMessage(CString strMessage); SendFile(CString strFilePath); ReceiveFile(); CloseConnection(); Error() ; 11. client.h file contain following functions: CreateSocket(); Connection (CString IPAddressOfServer ,int portNumber); SendMessage (CString strMessage) SendFile (CString strFilePath); ReceiveFile(); CloseConnection(); Error() ; 12. 13. Create an Object of Server class as : Server objServer Create an Object of Client class as : Client objClient
- 71 -
14.
15.
Call the CreateSocket() , ListenSocket() function for the Server object pass the port number for server.
Call the CreateSocket() , Connection() function for the Client object , in the connection function pass the IP address of the server and port number
given at server.
16. 17. 18. 19. 20. After the connection call the SendMessage () function from Server or Client
TCP.
Students can create their own GUI and can define their own parameters
21.
22.
after making use of the given classes and prove their programming skills. Thus socket processing can be carried out.
To see the functionality with sample executables use TCP Test Server.exe
23.
Run TCP Test Server.exe on one of the computer and pass port number.
- 72 -
24. 25.
Run TCP Test Client.exe on other computer and pass IP address of server computer and port number provided at server. Check the functionality by sending message and / or files.
Note: To see the code of specific function, open the server.cpp or client.cpp file & then check the code of the function.
- 73 -
- 74 -
EXPERIMENT 6
STYDY OF DATA ENCRYPTION AND DECRYPTION
- 75 -
SERVER
CLIENT-1
CLIENT-2
PORT-1
PORT-2
PORT-3
SWITCH
PORT-6
PORT-5
PORT-4
CLIENT-5
CLIENT-4
CLIENT-3
- 76 -
EXPERIMENT 6:
OBJECTIVE: Study of data encryption and decryption. EQUIPMENTS: LTS-01 trainer kit 2 Computers with win-2K / XP and Ethernet port available on them RJ-45 to RJ-45 LAN connecting cables L-SIM LAN protocol analyzer and simulator software PROCEDURE: 1.
2. 3. 4. 5. 6.
7.
8. 9.
10. 11.
Connect at least two computer LAN ports using RJ-45 to RJ-45 LAN connecting cables provided with the system to LTS-01 star topology ports. Switch on the LTS-01 & Computers. Run L-SIM software on both the computers, one should be server and another should be client. On the server computer select type of network as LAN. On the server computer select the topology as STAR and select protocol as Stop & Wait and click on create network button. Remote computer details will appear on the computers connected in network, server will be able to see client and client will be able to see server. Select the computer to whom data file is to be transferred, from the load button, previously stored/selected file information can be loaded or you can select any file, which is to be transmitted, if notepad text file is selected encryption information can be viewed very clearly for each packet formed for that file. File size will appear in the software window, select the packet size, inter packet delay and click OK. Total packets formed for that file will be indicated on computers, same details of file will appear on remote computer to which file is to be transmitted. Click on file transfer button to transfer file. Click on pause button to interrupt file transfer and click on encrypt/decrypt button to see file packet encrypted and decrypted.
- 77 -
12.
You will see actual file selected packet content and encrypted data content in encryption details window.
13.
You can type any text at the bottom box, which you want to encrypt and provide key text for encryption. Similarly same key can be typed again to decrypt and recover encrypted text. If the key at decryption stage differ from key at encryption stage, decrypted data will not be perfect as per
original data.
- 78 -
14.
To understand the working of how encryption took place you can view visual explanation of encryption and decryption process by clicking on visual help button.
15. 16.
17.
Visual help showing decryption procedure. You can resume file transfer by clicking on continue button.
Encrypted format of each packet can thus be seen by pausing the file
18. 19.
transfer at respective packet when it is under transmission state. File transfer from one computer to another will take place. To study programming of Cryptography with Encryption and Decryption
process sample executable file & program is provided inside program files
Lsim SampleApplication.zip.
20. When user extracts this folder he will find cryptography folder inside which
- 79 -
21.
If user runs the cryptography.exe file screen with browse option for selection of file to be encrypted and enter key for encryption option will get open for user to select the file and enter encryption key.
22.
23.
- 80 -
24.
25. 26.
for decryption is selected. To verify encryption and decrypted files user has to close the cryptography.exe file. Actual programming can be checked from cryptography.cpp program.
- 81 -
- 82 -
EXPERIMENT 7
STUDY OF TOKEN BUS AND TOKEN RING PROTOCOL
- 83 -
S RVER E
C I N 1 L ET
C I N 2 L ET
C I N 3 L ET
C I N 4 L ET
- 84 -
PO RT1
PO RT2
PO RT3
PO RT4
PO RT5
o polog y
EXPERIMENT 7:
OBJECTIVE: To study token bus and token ring protocol EQUIPMENTS: LTS-01 trainer kit 4 or more Computers with win-2K / XP and Ethernet port available on them RJ-45 to RJ-45 LAN connecting cables L-SIM LAN protocol analyzer and simulator software PROCEDURE: A. 1. 2. 3. 4. TOKEN BUS: Connect four or more computer LAN ports using RJ-45 to RJ-45 LAN connecting cables provided with the system to LTS-01 bus topology ports. Switch on the LTS-01 & Computers. Run L-SIM software on all the computers, one should be server and others should be client. Run the software in the sequence of connection i.e. server first followed by first client to last client. On the server computer select type of network as LAN.
5.
6.
7.
On the server computer select the topology as BUS, select protocol as Token Bus and select token activation time as desired, click on create network button. To just observe how token passes from one computer to another computer and effect of token time keep token duration from 5 to 40 seconds and to do actual file transfer keep token duration as 50 or 60 seconds. Remote computer details will appear on the computers connected in network, server will be able to see all clients and all clients will be able to see only server.
- 85 -
SERVER
CLIENT-1
PORT-1
PORT-2
PORT-4
PORT-3
CLIENT-2
- 86 -
8.
9.
10.
11. 12.
13.
Select the computer to whom data file is to be transferred, from the load button, previously stored/selected file information can be loaded or you can select any file, which is to be transmitted. File size will appear in the software window, select the packet size, inter packet delay and click OK. Total packets formed for that file will be indicated on computers, same details of file will appear on remote computer to which file is to be transmitted. Click on file transfer button to transfer file. File transfer from one computer to another will take place.
Remove connection of last client and see the effect on file transfer or token transfer. You will find that token will process till the client who is connected
14.
in network. Remove connection of client which is in between the server and last client and see the effect on file transfer or token transfer. You will find that token will process till the client who is connected in network from client and will not process from the client got disconnected from network. TOKEN RING: Connect four computer LAN ports using RJ-45 to RJ-45 LAN connecting cables provided with the system to LTS-01 ring topology ports. Switch on the LTS-01 & Computers. Run L-SIM software on all the computers, one should be server and other 3 should be client. Run the software in the sequence of connection i.e. server first followed by first client to last client. On the server computer select type of network as LAN.
B. 1. 2. 3. 4.
5.
On the server computer select the topology as RING, select protocol as Token Ring and select token activation time as desired, click on create network button.
- 87 -
6.
7.
8.
9.
10.
To just observe how token passes from one computer to another computer and effect of token time keep token duration from 5 to 40 seconds and to do actual file transfer keep token duration as 50 or 60 seconds. Remote computer details will appear on the computers connected in network, server will be able to see all clients and all clients will be able to see only server. Select the computer to whom data file is to be transferred, from the load button, previously stored/selected file information can be loaded or you can select any file, which is to be transmitted. File size will appear in the software window, select the packet size, inter packet delay and click OK. Total packets formed for that file will be indicated on computers, same
details of file will appear on remote computer to which file is to be
transmitted. Click on file transfer button to transfer file. File transfer from one computer to another will take place. To see the effect of ring break state remove any of the client from the
hardware and close L-SIM window for that client. Ring broken message will be prompted on server computer and network will get destroyed, you need to reconfigure the network. Since the network is created with logical ring
unplugging of computer.
- 88 -
EXPERIMENT 8
IMPLEMENTATION AND STUDY OF CSMA-CD PROTOCOL
- 89 -
SERVER
CLIENT-1
CLIENT-2
PORT-1
PORT-2
PORT-3
SWITCH
PORT-6
PORT-5
PORT-4
CLIENT-5
CLIENT-4
CLIENT-3
- 90 -
EXPERIMENT 8:
OBJECTIVE: Implementation and study of CSMA-CD protocol. EQUIPMENTS: LTS-01 trainer kit 3 Computers with win-2K / XP and Ethernet port available on them RJ-45 to RJ-45 LAN connecting cables L-SIM LAN protocol analyzer and simulator software PROCEDURE: 1.
2. 3. 4. 5. 6.
7.
8. 9.
10. 11.
Connect 3 or more computer LAN ports using RJ-45 to RJ-45 LAN connecting cables provided with the system to LTS-01 star topology ports. Switch on the LTS-01 & Computers. Run L-SIM software on all the computers, one should be server and others should be clients. On the server computer select type of network as LAN. On the server computer select the topology as STAR, select protocol as CSMA-CD click on create network button. Remote computer details will appear on the computers connected in network, server will be able to see all clients and all clients will be able to see only server. Select the server computer to whom data file is to be transferred from one of the client computer; from the load button, previously stored/selected file information can be loaded or you can select any file, which is to be transmitted. File size will appear in the software window, select the packet size, inter packet delay and click OK. Total packets formed for that file will be indicated on computers, same details of file will appear on remote computer to which file is to be transmitted. Click on file transfer button to transfer file. During file transfer process try to send file to server from another client computer, file transfer from second transmitter will also gets initiated.
- 91 -
12.
When packet from second sender collides with first sender it will be indicated as collision packet on server & Client-1.
- 92 -
13.
File from first sender will resume after some time and second sender file will be kept on hold till first file transfer gets completed.
14. 15.
Once the first sender file reached to server its display is refreshed and
cleared.
16. Multiple file transfer between various server-client combinations should be performed to observe throughput v/s packet size graph on transmitter
computer.
17. Close file transfer window and click on protocol analyzer and Network
18.
analyzer buttons on transmitter computer to view details of the log created. Under Network analyzer window click on Graph analyzer button.
- 93 -
19.
Graph for CSMA-CD protocol 20. 21. Detailed graph of throughput v/s packet size for the total file transfer activity will appear on graph window. This plot can be printed by clicking on print button.
- 94 -
EXPERIMENT 9
IMPLEMENTATION AND STUDY OF CSMA-CA PROTOCOL
- 95 -
SERVER
CLIENT-1
CLIENT-2
PORT-1
PORT-2
PORT-3
SWITCH
PORT-6
PORT-5
PORT-4
CLIENT-5
CLIENT-4
CLIENT-3
- 96 -
EXPERIMENT 9:
OBJECTIVE: Implementation and study of CSMA-CA protocol. EQUIPMENTS: LTS-01 trainer kit 3 Computers with win-2K / XP and Ethernet port available on them RJ-45 to RJ-45 LAN connecting cables L-SIM LAN protocol analyzer and simulator software PROCEDURE: 1.
2. 3. 4. 5. 6.
7. 8.
9.
10.
11.
Connect 3 or more computer LAN ports using RJ-45 to RJ-45 LAN connecting cables provided with the system to LTS-01 star topology ports. Switch on the LTS-01 & Computers. Run L-SIM software on all the computers, one should be server and others should be clients. On the server computer select type of network as LAN. On the server computer select the topology as STAR, select protocol as CSMA-CA click on create network button. Remote computer details will appear on the computers connected in network, server will be able to see all clients and all clients will be able to see only server. Click on the Send RTS button to get your computer into transmitter mode. Select the computer to whom data file is to be transferred, from the load button, previously stored/selected file information can be loaded or you can select any file, which is to be transmitted. File size will appear in the software window, select the packet size, inter packet delay and click OK. Total packets formed for that file will be indicated on computers, same details of file will appear on remote computer to which file is to be transmitted. Click on file transfer button to transfer file.
12.
During file transfer process try to get access to transmit file by clicking on
Send RTS button on other computers, you will be prompted with channel is busy message.
- 97 -
13. 14.
15.
Thus collision of two packets transmitted simultaneously from two senders is avoided. File transfer from one computer to another will take place.
Multiple file transfer between various server-client combinations should be performed to observe throughput v/s packet size graph on transmitter
computer.
16. Close file transfer window and click on protocol analyzer and Network
17. 18.
analyzer buttons on transmitter computer to view details of the log created. Under Network analyzer window click on Graph analyzer button. Calculate throughput and click on Plot graph button.
20.
will appear on graph window. This plot can be printed by clicking on print button.
- 98 -
EXPERIMENT 10
IMPLEMENTATION AND STUDY OF WIRELESS LAN
- 99 -
SERVER
CLIENT-1
ACCESS CARD
ACCESS CARD
ACCESS POINT
CLIENT-3
ACCESS CARD
ACCESS CARD
CLIENT-2
- 100 -
EXPERIMENT 10:
OBJECTIVE: Implementation and study of Wireless LAN. EQUIPMENTS: 3 or 4 Computers with win-2K / XP Access point with accessories Wireless LAN Access cards with USB driver installed on respective computers L-SIM LAN protocol analyzer and simulator software PROCEDURE: 1.
2. 3. 4.
5.
Connect Access point to power outlet and switch it on. Connect USB wireless access cards to computer USB ports and check for driver installed on respective computers. See appendix for installation guide of LAN access cards. You will find wireless LAN detection on your computers, Assign IP address to the detected wireless LAN and connect it. Connection of wireless LAN will be indicated on your computers. Run L-SIM software on all the computers, one should be server and others should be clients.
6. 7. 8.
9.
10.
On the server computer select type of network as WLAN. On the server computer select the topology as STAR, select protocol as CSMA-CA click on create network button. Remote computer details will appear on the computers connected in network, server will be able to see all clients and all clients will be able to see only server. Click on the Send RTS button to get your computer into transmitter mode. Select the computer to whom data file is to be transferred, from the load
button, previously stored/selected file information can be loaded or you can
11.
select any file, which is to be transmitted. File size will appear in the software window, select the packet size, inter packet delay and click OK.
- 101 -
12.
Total packets formed for that file will be indicated on computers, same
details of file will appear on remote computer to which file is to be
13.
14. 15.
During file transfer process try to get access to transmit file by clicking on
Send RTS button, you will be prompted with channel is busy message.
Thus collision of two packets transmitted simultaneously from two senders
is avoided.
- 102 -
16. 17.
File transfer from one computer to another will take place. Multiple file transfer between various server-client combinations should be
performed to observe throughput v/s packet size graph on transmitter
computer.
18. Close file transfer window and click on protocol analyzer and Network
19. 20.
analyzer buttons on transmitter computer to view details of the log created. Under Network analyzer window click on Graph analyzer button. Calculate throughput and click on Plot graph button.
21.
Detailed graph of throughput v/s packet size for the total file transfer activity
22.
will appear on graph window. This plot can be printed by clicking on print button.
- 103 -
- 104 -
EXPERIMENT 11111
IMPLEMENTATION OF DISTANCE VECTOR ROUTING ALGORITHM
- 105 -
- 106 -
EXPERIMENT 11:
OBJECTIVE: Implementation of distance vector routing algorithm. EQUIPMENTS: N-SIM Computer with win-2K / XP PROCEDURE: 1. Run N-SIM software from your computer. 2. To check working of distance vector routing algorithm in the form of animated representation click on distance vector routing under routing protocols.
3. 4.
You can study the working of distance vector routing algorithm through this animated movie. To implement this algorithm click on algorithms under menu and click on distance vector routing.
- 107 -
5.
Add the number of routers you want to, select one by one, maximum 8 routers can be added, all the added routers will appear in the window.
6. 7. 8. 9.
Click configure button to define the links between pair of routers and define its cost in kilometers. Once all the possible pairs have been defined click save button to save the configuration defined by you. Depending on the configuration you will see all the possible links defined by you are implemented and drawn in the screen near the routers added. You can edit the configuration at any time by clicking on the value of the router number or cost.
- 108 -
10.
To simulate and find out shortest path select the source and destination routers.
11.
Click on simulate button to start the algorithm, this will calculate the
- 109 -
12. 13.
Click on the result button to see the parameters for shortest path. Click on graph button to plot the readings against the various parameters.
- 110 -
EXPERIMENT 12
IMPLEMENTATION OF LINK STATE ROUTING ALGORITHM
- 111 -
- 112 -
EXPERIMENT 12:
OBJECTIVE: Implementation of link state routing algorithm. EQUIPMENTS: N-SIM Computer with win-2K / XP PROCEDURE: 1. Run N-SIM software from your computer. 2. To check working of state routing algorithm in the form of animated representation click on state routing under routing protocols.
3. 4.
You can study the working of state routing algorithm through this animated movie. To implement this algorithm click on algorithms under menu and click on state routing.
- 113 -
5.
Add the number of routers you want to, select one by one, maximum 8 routers can be added, all the added routers will appear in the window.
6. 7. 8. 9.
Click configure button to define the links between pair of routers and define its cost in kilometers. Once all the possible pairs have been defined click save button to save the configuration defined by you. Depending on the configuration you will see all the possible links defined by you are implemented and drawn in the screen near the routers added. You can edit the configuration at any time by clicking on the value of the router number or cost.
- 114 -
10.
To simulate and find out shortest path select the source and destination routers.
11.
Click on simulate button to start the algorithm, this will calculate the
- 115 -
12. 13.
Click on the result button to see the parameters for shortest path. Click on graph button to plot the readings against the various parameters.
- 116 -
APPENDIX
TCP SOCKET PROCESSING AND CRYPTOGRAPHY C++ SAMPLE PROGRAMS
- 117 -
- 118 -
APPENDIX
TCP SOCKET PROCESSING C++ SAMPLE PROGRAMS: 1. TCP TEST SERVER (SERVER.CPP):
int int
IsConnectionAccepted = 0 ; // 0 = Connection is not accepted, 1 = Connection is accepted IsCreated = 0 ; // 0 = Server not Created , 1 = Server Created strFileName; // Name of the File to Send NumberOfCharReceived; //Show the number of characters received buffer[5000]; // This is used to receive data flag=0; //Flag is used for distinguishing between file data and message. fileWrite=0; // fileWrite is used to write file fileNameWrite=0; // fileNameWrite is used to write file name IsClientClosed=0; // 0 = Client is not closed, 1= Client is closed IsServerClosed=0; // 0 = Server is not closed, 1= Server is closed
Server::Server()
{
AfxSocketInit();
}
Server::~Server()
{ }
Error() ;
}
else
{
- 119 -
} }
void Server::ListenSocket()
{
if((IsConnectionAccepted==0)||(IsServerClosed!=0)||(IsClientClosed!=0)) { AfxMessageBox("Connection not established "); } else { CFile cfile_Object1; int i=cfile_Object1.Open(fileNamePath, CFile::modeRead); if(i==0)
{
else
{
Sleep(2000); FileFlag="FileNameSending"; ServerObject1.Send(FileFlag,FileFlag.GetLength()); Sleep(2000); TRY{ CFile cfile_Object; cfile_Object.Open(fileNamePath, CFile::modeRead); CString fileName=cfile_Object.GetFileName(); ServerObject1.Send(fileName,fileName.GetLength()); Sleep(2000); int fileLength=cfile_Object.GetLength(); CString str1; str1.Format("%d",fileLength); char charArray[5000]; int FileBegin=0; while(FileBegin<fileLength)
{
pEx->ReportError();
}
END_CATCH FileFlag="File has Received"; ServerObject1.Send(FileFlag,FileFlag.GetLength());//Sending end of file }//end of second else } //end of first else }//end of SendFile Method void Server::ReceiveFile()
{
//
AfxMessageBox(" file is being received"); CFile cfile_object; CString DestinationName="c:\\"; DestinationName.operator +=(strFileName);//Writing file path where file is to be written.
- 121 -
void Server::CloseConnection()
{
if(IsCreated) { ServerObject1.Close(); AfxMessageBox("Connection has closed"); IsServerClosed++; } else { AfxMessageBox("Server has not Created"); }
}
void Server::Error()
{
LPVOID lpMsgBuf; FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, GetLastError(), 0, // Default language (LPTSTR) &lpMsgBuf, 0, NULL ); // Process any inserts in lpMsgBuf. // ... // Display the string. MessageBox( NULL, (LPCTSTR)lpMsgBuf, "Error", MB_OK | MB_ICONINFORMATION ); // Free the buffer. LocalFree( lpMsgBuf );
}
NumberOfCharReceived = Receive(buffer, 5000); buffer[NumberOfCharReceived]='\0'; if(!strcmp(buffer,"FileSendingReady")) { flag=1; } if(!strcmp(buffer,"File has Received")) { flag=0; fileWrite--; } if(flag==0) { AfxMessageBox(buffer);//it is message
}
if (fileWrite==1) { //AfxMessageBox ("it is file data"); ReceiveFile(); } if(fileNameWrite==1) { //AfxMessageBox("u r Receiving file name") ; strFileName=buffer; fileNameWrite--; fileWrite++; } if(!strcmp(buffer,"FileNameSending")) { fileNameWrite++; } switch (NumberOfCharReceived)
{
break; default:
{ } }
2.
public: Server(); ~Server(); void CreateSocket(int portNumber); // This function is used to create socket void ListenSocket(); // This function is used to listen port by server void SendMessage(CString strMessage); // This function is used to send the message void SendFile(CString strFilePath); // This function is used to send the file void ReceiveFile(); // This function is used to receive the file void CloseConnection(); // This function is used to close the connection void Error() ; // Error Handler // Overrides public: //Message Handler from CSocket Base class virtual void OnAccept(int nErrorCode); virtual void OnReceive(int nErrorCode); virtual void OnClose(int nErrorCode);
};
- 124 -
3.
#include "stdafx.h" #include "Client.h" Client ClientObject; CString FileName; // name of file that is to be sent int NumberOfCharReceived; //it gives number of character received from buffer char buffer[5000]; //buffer is used to store data in buffer static flag=0; //Flag is used for distinguishing between file data and message. static int fileWrite=0; // file Write is used to write file static int fileNameWrite=0; //fileNameWrite is used to write file name int IsCreated = 0 ; //0=Client Socket is not created,1=Client Socket is created int IsServerClosed = 0 ; // 0 = Server is not close ,1=Server is close int IsClientClosed=0; // 0 = Client is not close ,1=Client is close Client::Client()
{
AfxSocketInit();
}
Client::~Client()
{ }
void Client::CreateSocket()
{
int ReturnValue =ClientObject.Create();; if(ReturnValue==0 ) { Error() ; } else { AfxMessageBox("Client Socket has Created"); IsCreated++ ; }
}
int i=ClientObject.Connect(ipAddress,port); if(i) AfxMessageBox("Connection has Created"); else AfxMessageBox("Connection has not Created");
}
- 125 -
else
{
cfile_Object1.Close(); //AfxMessageBox("U r inside SendFile method"); CString FileFlag="FileSendingReady"; ClientObject.Send(FileFlag,FileFlag.GetLength());//flag for that file is going to send Sleep(2000); FileFlag="FileNameSending"; ClientObject.Send(FileFlag,FileFlag.GetLength());//sending file name Sleep(2000); TRY{ CFile cfile_Object; cfile_Object.Open(fileNamePath, CFile::modeRead); CString fileName=cfile_Object.GetFileName(); //AfxMessageBox(fileName); ClientObject.Send(fileName,fileName.GetLength()); Sleep(2000); int fileLength=cfile_Object.GetLength(); CString str1; str1.Format("%d",fileLength); char charArray[5000]; int fileBegin=0;
- 126 -
while(fileBegin<fileLength)
{
pEx->ReportError();
}
END_CATCH FileFlag="File has Received"; ClientObject.Send(FileFlag,FileFlag.GetLength()); }//end of first else }//end of second else }//end of SendFile method void Client::ReceiveFile()
{
//AfxMessageBox(" file is being received"); CFile cfile_object; CString DestinationName="c:\\"; DestinationName.operator +=(FileName);//Writing file path where file is to be written. cfile_object.Open(DestinationName, CFile::modeCreate|CFile::modeNoTruncate|CFile::modeWrite);//file opening cfile_object.SeekToEnd(); cfile_object.Write((const void *)buffer,NumberOfCharReceived); //file writing
}
if(IsCreated) { ClientObject.Close(); AfxMessageBox("Connection has closed"); IsClientClosed++; } else { AfxMessageBox("Client has not Created"); }
}
- 127 -
void Client::Error()
{
LPVOID lpMsgBuf; FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, GetLastError(), 0, // Default language (LPTSTR) &lpMsgBuf, 0, NULL ); // Process any inserts in lpMsgBuf. // ... // Display the string. MessageBox( NULL, (LPCTSTR)lpMsgBuf, "Error", MB_OK | MB_ICONINFORMATION ); // Free the buffer. LocalFree( lpMsgBuf );
}
flag=1;
}
flag=0; fileWrite--;
}
if(flag==0)
{
AfxMessageBox(buffer);//it is message
}
if (fileWrite==1)
{
if(fileNameWrite==1)
{
fileNameWrite--; fileWrite++;
}
if(!strcmp(buffer,"FileNameSending"))
{
fileNameWrite++;
}
switch (NumberOfCharReceived)
{
break; default:
{ } }
4.
public: Client(); virtual ~Client(); void CreateSocket(); // This function is used to create socket void Connection(CString IPAddressOfServer,int portNumber); // This function is used to establish connection void SendMessage(CString strMessage); // This function is used to send the message void SendFile(CString strFilePath); // This function is used to send the file
NETWORK LABORATORY & DATA COMMUNICATION
void ReceiveFile(); // This function is used to receive the file void CloseConnection(); // This function is used to close the connection void Error() ; // Error Handler //Message Handler from CSocket Base class public: virtual void OnReceive(int nErrorCode); virtual void OnClose(int nErrorCode);
};
- 130 -
// NewEncrytAndDecryptFile.cpp : Defines the class behaviors for the application.// #include "stdafx.h" #include "NewEncrytAndDecryptFile.h" #include "NewEncrytAndDecryptFileDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CNewEncrytAndDecryptFileApp BEGIN_MESSAGE_MAP(CNewEncrytAndDecryptFileApp, CWinApp) //{{AFX_MSG_MAP(CNewEncrytAndDecryptFileApp) // NOTE - the ClassWizard will add and remove mapping macros here. // DO NOT EDIT what you see in these blocks of generated code! //}}AFX_MSG ON_COMMAND(ID_HELP, CWinApp::OnHelp) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CNewEncrytAndDecryptFileApp construction CNewEncrytAndDecryptFileApp::CNewEncrytAndDecryptFileApp()
{
// TODO: add construction code here, // Place all significant initialization in InitInstance
}
///////////////////////////////////////////////////////////////////////////// // The one and only CNewEncrytAndDecryptFileApp object CNewEncrytAndDecryptFileApp theApp; ///////////////////////////////////////////////////////////////////////////// // CNewEncrytAndDecryptFileApp initialization BOOL CNewEncrytAndDecryptFileApp::InitInstance()
{
AfxEnableControlContainer(); // Standard initialization // If you are not using these features and wish to reduce the size // of your final executable, you should remove from the following // the specific initialization routines you do not need. #ifdef _AFXDLL Enable3dControls(); // Call this when using MFC in a shared DLL #else Enable3dControlsStatic(); // Call this when linking to MFC statically
- 131 NETWORK LABORATORY & DATA COMMUNICATION
#endif CNewEncrytAndDecryptFileDlg dlg; m_pMainWnd = &dlg; int nResponse = dlg.DoModal(); if (nResponse == IDOK) { // TODO: Place code here to handle when the dialog is // dismissed with OK } else if (nResponse == IDCANCEL) {
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel } // Since the dialog has been closed, return FALSE so that we exit the // application, rather than start the application's message pump. return FALSE;
}
2.
NEWENCRYPTANDDECRYPTFILE.H:
// NewEncrytAndDecryptFile.h : main header file for the NEWENCRYTANDDECRYPTFILE application // #if !defined(AFX_NEWENCRYTANDDECRYPTFILE_H__D78F5474_1A0E_4968_80 81_77A2B51A088C__INCLUDED_) #define AFX_NEWENCRYTANDDECRYPTFILE_H__D78F5474_1A0E_4968_8081_77A2 B51A088C__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 #ifndef __AFXWIN_H__ #error include 'stdafx.h' before including this file for PCH #endif #include "resource.h" // main symbols ///////////////////////////////////////////////////////////////////////////// // CNewEncrytAndDecryptFileApp: // See NewEncrytAndDecryptFile.cpp for the implementation of this class // class CNewEncrytAndDecryptFileApp : public CWinApp
{
//{{AFX_VIRTUAL(CNewEncrytAndDecryptFileApp) public: virtual BOOL InitInstance(); //}}AFX_VIRTUAL // Implementation //{{AFX_MSG(CNewEncrytAndDecryptFileApp) // NOTE - the ClassWizard will add and remove member functions here. // DO NOT EDIT what you see in these blocks of generated code ! //}}AFX_MSG DECLARE_MESSAGE_MAP()
};
///////////////////////////////////////////////////////////////////////////// //{{AFX_INSERT_LOCATION}} // Microsoft Visual C++ will insert additional declarations immediately before the previous line. #endif // !defined(AFX_NEWENCRYTANDDECRYPTFILE_H__D78F5474_1A0E_4968_80 81_77A2B51A088C__INCLUDED_)