Elective Lab:Iii: Assignment No. 8
Elective Lab:Iii: Assignment No. 8
Elective Lab:Iii: Assignment No. 8
ASSIGNMENT NO. 8
Problem Statement:
Install, configure APACHE server and deployed an application on Raspberry Pi/Beagle
board.Write client applications to get services from the server application.
Hardware Requirements:
Raspberry-pi
Software Requirements:
Objectives:
Theory:
Apache is a popular web server application you can install on the Raspberry Pi to
allow it to serve web pages.
On its own, Apache can serve HTML files over HTTP, and with additional
modules can serve dynamic web pages using scripting languages such as PHP.
Install Apache
First, update the available packages by typing the following command into the
Terminal:
By default, Apache puts a test HTML file in the web folder. This default web page
is served when you browse to http://localhost/ on the Pi itself,
or http://192.168.1.10 (whatever the Pi's IP address is) from another computer on
the network. To find the Pi's IP address, type hostname -I at the command line (or
read more about finding your IP address).
Browse to the default web page either on the Pi or from another computer on the
network and you should see the following:
This default web page is just an HTML file on the filesystem. It is located
at /var/www/html/index.html.
Navigate to this directory in a terminal window and have a look at what's inside:
cd /var/www/html
ls -al
total 12
This shows that by default there is one file in /var/www/html/ called index.htmland it is owned
by the root user (as is the enclosing folder). In order to edit the file, you need to change its
ownership to your own username. Change the owner of the file (the default pi user is assumed
here) using sudo chown pi: index.html.
You can now try editing this file and then refreshing the browser to see the web page change.
If you know HTML you can put your own HTML files and other assets in this directory and
serve them as a website on your local network.
Socket :
• Sockets may communicate within a process, between processes on the same machine, or
• Sockets may be implemented over a number of different channel types: Unix domain sockets,
TCP, UDP, and so on.
• The socket library provides specific classes for handling the common transports as well as a
syntax:
• Once you have socket object, then you can use required functions to create your client or server
program. Socket MTo create a socket, you must use the socket.socket() function in socket
module, which has the general
syntax:
SOCK_DGRAM.
• Once you have socket object, then you can use required functions to create your client or server
program module.
s.bind() This method binds address (hostname, port number pair) to socket.
s.listen() This method sets up and start TCP listener.
s.accept() This passively accept TCP client connection, waiting until connection
arrives (blocking).
Conclusion:
import socket
s=socket.socket()
s.connect(("192.168.43.164",1234))
s.close()
import socket
import Adafruit_DHT
s=socket.socket()
s.bind(("192.168.43.164",1234))
s.listen(5)
while True:
c,addr=s.accept()
hum,temp=Adafruit_DHT.read_retry(11,4)
c.send(str(temp))
c.close()