Faculty of Engineering and Technology Department of Electrical and Computer Engineering Communication and Computer Networks ENCS433
Faculty of Engineering and Technology Department of Electrical and Computer Engineering Communication and Computer Networks ENCS433
Faculty of Engineering and Technology Department of Electrical and Computer Engineering Communication and Computer Networks ENCS433
Project#1
2
1) Abstract :
This project aims to:
Build a simple network using a cable between two computers.
Build a simple network using an access point between two computers.
Learn more about ping, tracert and nslookup commands and what is
their output.
Implement a simple but a complete web server in python or java
listening on port 1900.
3
2) Theory :
1) Simple network between two computers:-
4
2) ping, tracert and nslookup commands:
a) ping command: is a Command Prompt command used to test the
ability of the source computer to reach a specified destination
computer. The ping command is usually used as a simple way to
verify that a computer can communicate over the network with
another computer or network device.
5
3) Simple Complete web server in java:
Web server: is a computer where the web content is stored. Basically
web server is used to host the web sites but there exists other web
servers also such as gaming, storage, FTP, email etc.
Java is one of the most used programming languages in the World. The
JDK comes with a lot of exciting features. In that video, we are going to
use the ServerSocket and the Socket classes to create a simple HTTP
Web Server in Java.
6
3) Procedure & Discussion:
1) Building a Simple network between two computers:-
a) Simple network using a LAN cable:
1- Two computers were connected using a LAN cable as shown in pic1.
Pic: 1
7
2- The directory of control panel was opened on the first computer
(Control Panel\Network and Internet\Network and Sharing
Center\Advanced sharing settings).
3- Sharing was turned on so anyone with network access can read and
write files in the public folders.
4- Password protected sharing was turned off as shown in figure: 1.1.
Fig: 1.1
8
5- The directory of control panel was opened.
(Control Panel\Network and Internet\Network and Sharing
Center).
6- The internet protocol version 4 (TCP/IPv4) properties was set as
shown in figure: 1.2.
Fig: 1.2
7- Previous steps(2-6) were repeated to the second computer.
Switch 192.168.1.7 by 192.168.1.8.
9
8- A file of size 634 MB was sent from the first computer to the
second.
9- The time of sending the file was obtained 58.36 seconds as shown
in figure: 1.3 and figure: 1.4.
10
b) Simple network using a access point:
1- Two computers were connected using a hotspot mobile.
2- The IP address of the first computer was: 192.168.43.186 and the
IP address of the second computer was: 192.168.43.4 as shown in
figure: 1.5 and figure: 1.6.
Fig: 1.5
Fig: 1.6
3- A file of size 634 MB was sent from the first computer to the
second.
11
4- The time of sending the file was obtained 4 minutes and 33.76
seconds as shown in figure: 1.7 and figure: 1.8.
12
2) ping, tracert and nslookup commands:-
a) ping command:
Fig: 2.1
13
b) tracert command:
Fig: 2.2
From these results you can see that it took between 200 and 217
milliseconds to retrieve data from the destination server, as shown in
the last hop.
14
c) nslookup command:
Fig: 2.3
stanfordhs17.wpengine.com.
lbmaster-90886.wpengine.com.
15
3) Implementation of a simple complete web server in java:-
1- The server was implemented in java programming language as follow:-
// A Java program for a Server
import java.net.*;
import java.util.*;
import java.io.*;
public class Server {
private Socket socket = null;
private ServerSocket server = null;
private Scanner scan = null;
private PrintWriter print=null;
public Server(int port) {
//waits for a connection
try {
server = new ServerSocket(port);
System.out.println("Server started");
System.out.println("Waiting for a client ...");
socket = server.accept();
System.out.println("Client accepted");
System.out.println("------------------------------------------");
// takes input from the client socket
scan = new Scanner(socket.getInputStream());
print=new PrintWriter(socket.getOutputStream(),true);
String line = "";
try {
int sb=0,sa=0;
while (true){
sb=line.length();
line = line + scan.nextLine();
sa=line.length();
//this mean nothing to read
if(sa==sb)break;
16
line=line+"\n";
}
//to check if the request doesn't start with GET
//line=line.substring(1);
System.out.println(line);
if(line.startsWith("GET")){
print.println("HTTP/1.1 200 OK");
print.println("Connection: close");
print.println("Date: " + new Date());
print.println("Content-Type: text/html");
print.println();
print.println("
<html>
<head>
<title>Simple Webserver</title>
</head>
<body>
<table border='1'>
<thead>
<td>Name</td>
<td>ID</td>
</thead>
<tr>
<td><b>Layth Abufarhah</b></td>
<td><b>1162636</b></td>
</tr>
<tr>
<td><b>Loris Tarazi</b></td>
<td><b>1170691</b></td>
</tr>
<tr><td><b>Ali Shoman</b></td>
<td><b>1171204</b></td>
</tr>
17
</table>
<p>Welcome to <span style='color:green'>Computer
Networks<span></p>
<p>IP Address: "+socket.getInetAddress()+"</p><p>Port Number:
"+socket.getPort()+"
</p>
</body>
</html>
");
}else{
print.println("HTTP/1.1 405 Method Not
Allowed");
print.println("Cache-Control: no-cache");
print.println("Pragma: no-cache");
print.println("Date: " + new Date());
print.println("Content-Type:
application/json;
charset=utf-8");
print.println();
print.println("{"+"\"Message\""+":"+"\"The
requested resource does not support http method.\""+"}");
}
} catch (Exception i) {
System.out.println(i);
}
System.out.println("Closing connection");
// close connection
socket.close();
scan.close();
} catch (IOException i) {
System.out.println(i);
}
18
}
public static void main(String args[]) {
Server server = new Server(1900);
}
}
2- The java file was compiled, this mean that the server was ready and
waiting to serve a client’s requests.
3- A Get message request was sent from the client (firefox browser) after
accepting from the same computer.
4- An appropriate message was responded to the browser to display
(html file).
Figure: 3.1 show the request message.
Figure: 3.2 show the displayed response.
Fig: 3.1
19
Fig: 3.2
20
Fig: 3.3
Fig: 3.4
Fig: 3.5
21
7- A mobile was connected to the same network with computer.
8- Ipconfig command was used to get the IP address of the computer as
shown in figure: 3.6.
Fig: 3.6
9- A Get message request was sent from the client (chrome browser)
after accepting from the mobile.
10- An appropriate message was responded to the browser to display
(html file).
Fig: 3.7
22
Fig: 3.8
23
4) Conclusion & Feedback:
In this project, we became familiar with simple networks and the
connections of computers and we also learned more about some commands
like ping, tracert and nslookup, and how to implement a simple web server.
This project was useful as we learned to deal with networks and their
connections and to see a simple example of what we learned in
communication and computer networks course so it was very exciting.
24
5) References:
https://www.lifewire.com
date: 24/10/2019.
https://www.online-tech-tips.com
date: 24/10/2019.
https://techwiser.com
date: 24/10/2019.
https://dart.dev
date: 25/10/2019.
https://www.ibm.com
date: 25/10/2019.
25
6) Appendix:
26