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
  • Powerful Essays

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

    • 3806 Words
    • 14 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
  • Satisfactory Essays

    It 240 Appendix F

    • 260 Words
    • 2 Pages

    Transmission Control Protocol / Internet Protocol (TCP/IP) TCP is the protocol used in networking that provides a connection-oriented, reliable way for applications to communicate large amount of data at one time over a network. IP is a connectionless protocol responsible for addressing network devices, and routing packets between…

    • 260 Words
    • 2 Pages
    Satisfactory 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

    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

    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
  • Powerful Essays

    Customer hereby engages the services of the Developer for the purpose of designing, creating, testing and delivering a fully functional Web Site, to be delivered to the Customer in the form of Hypertext Markup Language (“HTML”), JAVA and/or FLASH languages, most current version, which meets the specifications set forth herein and which is fully ready and operational upon placement on a server and creation of necessary connections for availability on the World Wide Web.…

    • 4332 Words
    • 18 Pages
    Powerful 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

    NT1210 Unit 2

    • 443 Words
    • 2 Pages

    7. Web Server - software that stores web pages and web objects, listens for requests for those pages, and sends the contents of those pages/objects to clients.…

    • 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
  • Satisfactory Essays

    Sockets are a key part of Unix and Windows-based operating systems. They make it easy for software developers to create network-enabled programs. Instead of constructing network connections from scratch for each program they write, developers can just include sockets in their programs. The sockets allow the programs to use the operating system's built-in commands to handle networking functions. Because they are used for a number of different network protocols (i.e. HTTP, FTP, telnet, and e-mail), many sockets can be open at one time.…

    • 349 Words
    • 2 Pages
    Satisfactory 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