Preview

CN ASS 3

Good Essays
Open Document
Open Document
867 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
CN ASS 3
COMPUTER NETWORKS
LAB ASSIGNMENT : 3

Aim :- Web Server :
We will learn the basics of socket programming for TCP connections in
Python, how to create a socket, bind it to a specific address and port, as well as send and receive a HTTP packet. We will also learn some basics of HTTP header format.

Code :Below you will find the skeleton code for the Web server. You are to complete the skeleton code. The places where you need to fill in code are marked with #Fill in start and #Fill in end. Each place may require one or more lines of code.

Code in Python :#import socket module from socket import * serverSocket = socket(AF_INET, SOCK_STREAM)
#Prepare a sever socket
#Fill in start serverSocket.bind(('',8647)) serverSocket.listen(1)
#Fill in end while True:
#Establish the connection print 'Ready to serve...' connectionSocket, addr = serverSocket.accept() try: #Fill in start message = connectionSocket.recv(1024) if not message: continue #Fill in end filename = message.split()[1] print filename[1:] f = open(filename[1:]) outputdata = f.read()
#Send one HTTP header line into socket
#Fill in start headerLine = "HTTP/1.1 200 OK Content-type:text/html; charset=utf-8\n\n" connectionSocket.send(headerLine.encode()) print outputdata
#Fill in end
#Send the content of the requested file to the client for i in range(0, len(outputdata)): connectionSocket.send(outputdata[i]) connectionSocket.close() except IOError:
#Send response message for file not found
#Fill in start pass print "404 Not Found" connectionSocket.send("HTTP/1.1 404 Not Found\n\n")
#Fill in end
#Close client socket
#Fill in start connectionSocket.close() #Fill in end serverSocket.close() Output :-

Fig : 1- Skeleton Code ( with #Fill in Start and ##Fill in end ) written in
Python shell

Fig : 2- Running the Python Shell Code in Server local host :
( Server Ipv4 : 192.168.0.4 )

Fig : 3- HTML Page displayed on Server Local Host Ipv4 : 192.168.0.4

Fig : 4- After Accessing Welcome.Html Page from Another Host

You May Also Find These Documents Helpful

  • Good Essays

    Listed below is an example of one with the name within it. Left click the box with code inside. Once clicked a bold black box will outline the rectangle of G2 and at the bottom right of the G2 box there will be a small square. Left click and drag down this square until it reaches the last row with data in it. Once the code is dragged down it will be placed into each row in column G of the bolded dragged down area.…

    • 414 Words
    • 2 Pages
    Good Essays
  • Satisfactory Essays

    Instructions: Only enter data in the yellow boxes. The remaining areas are already completed for you.…

    • 448 Words
    • 9 Pages
    Satisfactory Essays
  • Good Essays

    nt1230

    • 905 Words
    • 6 Pages

    Because this is only a test deployment, you will be using a Windows 7 computer to function as the web server. In Exercise 5.1 you install Internet Information Services on your workstation and configure it to host two web sites.…

    • 905 Words
    • 6 Pages
    Good Essays
  • Powerful Essays

    This document is a functional document set for that web design project. It follows the…

    • 3806 Words
    • 14 Pages
    Powerful Essays
  • Powerful Essays

    TCP / IP Model - provides end-to-end connectivity specifying how data should be formatted, addressed, transmitted, routed and received at the destination. This functionality has been organized into four abstraction layers which are used to sort all related protocols according to the scope of networking involved.[1][2] From lowest to highest, the layers are the link layer, containing communication technologies for a single network segment (link), the internet layer, connecting hosts across independent networks, thus establishing internetworking.…

    • 559 Words
    • 3 Pages
    Powerful Essays
  • Satisfactory Essays

    HTTP: Hypertext Transfer Protocol, The protocol used by web browsers and web servers to define the format of URLs (web addresses) and the messages used to exchange web objects.…

    • 539 Words
    • 3 Pages
    Satisfactory Essays
  • Powerful Essays

    Ass 208 1

    • 1596 Words
    • 28 Pages

    of the actions taken and you will prepare materials to enhance the safety awareness of…

    • 1596 Words
    • 28 Pages
    Powerful Essays
  • Good Essays

    Securing Windows Media

    • 481 Words
    • 2 Pages

    | Used for delivering data packets to clients that are streaming by using MMSU. Open only the necessary number of ports.…

    • 481 Words
    • 2 Pages
    Good Essays
  • Good Essays

    Paragraph and Arrow Ref

    • 3374 Words
    • 22 Pages

    2. The ____ as shown in the accompanying figure is a formatting mark that indicates where the ____ was…

    • 3374 Words
    • 22 Pages
    Good Essays
  • Satisfactory Essays

    Fbi Notes

    • 517 Words
    • 3 Pages

    Based on the example above, complete the following outline on a separate sheet of paper. You may type it or use pencil or pen.…

    • 517 Words
    • 3 Pages
    Satisfactory Essays
  • Good Essays

    In this exercise, you will test the functionality of the web server you just installed.…

    • 970 Words
    • 6 Pages
    Good Essays
  • Good Essays

    BIOL130

    • 22051 Words
    • 89 Pages

    begins with an outline for the module. A number, a letter and another number are used to…

    • 22051 Words
    • 89 Pages
    Good Essays
  • Good Essays

    NT1210 Unit 2

    • 443 Words
    • 2 Pages

    12. HTTP - The protocol used by web browsers and web servers to define the format of URLs (web addresses) and the messages used to exchange…

    • 443 Words
    • 2 Pages
    Good Essays
  • Good Essays

    This is what was actually done or is going to be done. It may need a diagram, in which case it should be drawn using a ruler and pencil and it must be labelled. It should be set out so that someone else can easily understand the process.…

    • 343 Words
    • 2 Pages
    Good Essays
  • Good Essays

    past tense

    • 1360 Words
    • 6 Pages

    To write, double click left on the box, then right click and choose ADD TEXT. Furture is done for you as an example: 9 points…

    • 1360 Words
    • 6 Pages
    Good Essays