1

My project is telemedecine that means i have to create a web server and get values from my sensors and affiche them into web page

So , I ask any ideas to make a simple web server ?

my scripts maked with python so i think the webserver should be with python ?

Any simple tutorial please ?

closed as off-topic by goldilocks Aug 3 '16 at 5:12

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question does not appear to be specific to the Raspberry Pi within the scope defined in the help center." – goldilocks
If this question can be reworded to fit the rules in the help center, please edit the question.

  • Welcome -- but this is not really a pi-specific question since python and web servers are not unique to the hardware. General programming questions belong on our larger parent site, Stack Overflow (where there are currently 600+ K questions tagged "python", more than 40x our total volume). – goldilocks Aug 3 '16 at 5:12
  • A few quick pointers though: 1) Technically you do not need a python web server to run/control a python script/process, although it is not a bad idea to integrate them if that is the primary purpose of the server; 2) Web services in python are generally implemented using frameworks such as django or flask. – goldilocks Aug 3 '16 at 5:12
1

using only the socket module, below is a web server with a lot of comments to help you understand what is happening:

import socket #imports a module named "socket"

HOST, PORT = '', 80 #defines the host as blank, which tells the server to listen on all possible ips, and defines the port as 80

listen_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)# creates the socket
listen_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
#SO_REUSEADDR mainly changes how wildcard addresses are treated when searching for conflicts. Without SO_REUSEADDR, binding socketA to 0.0.0.0:21 and then binding socketB to 192.168.0.1:21 will fail (with error EADDRINUSE),
listen_socket.bind((HOST, PORT)) #tells the socket which ip's and port to listen to
listen_socket.listen(1) #indicates the number of servers to create
while True: #creates an infinite loop
    client_connection, client_address = listen_socket.accept() #tells the server to accept any incoming connections
    request = client_connection.recv(1024) #proccesses the incoming data into a string
    print request #prints that string

    http_response = """\
HTTP/1.1 200 OK

mohammad made this
"""
    client_connection.sendall(http_response) #returns a string of data to the client
    client_connection.close() # closes the clients connection
  • thanks for the idea , but i need a web page that show my sensors values with some designs . – RouiniHo Aug 3 '16 at 4:51
  • @RouiniHo you did not indicate how the values are being passed to the web server and what do you mean by designs? this was not part of the initial question – Mohammad Ali Aug 3 '16 at 4:52
  • yes im sorry , i dont know yet how the values will be passed to the web server . i find some solutions with cgi but i dont know yet if its the simple solution – RouiniHo Aug 3 '16 at 5:01
  • @RouiniHo are your values simply strings? – Mohammad Ali Aug 3 '16 at 5:01
  • my values are simple numbers variable from sensor – RouiniHo Aug 3 '16 at 5:05

Not the answer you're looking for? Browse other questions tagged or ask your own question.