tempserver.py – Server side for temperature measurement

#! /usr/bin/python3

import socketserver
import pymysql

class MyUDPHandler(socketserver.BaseRequestHandler):
    def handle(self):
        data = self.request[0].strip()
        socket = self.request[1]

#Write temperature on file
        client =  self.client_address[0]
        filename = '/tmp/' + client
        f = open(filename, 'w')
        f.write(data.decode('utf-8'))
        f.close

if __name__ == "__main__":
    HOST, PORT = "192.168.0.100", 3000
    server = socketserver.UDPServer((HOST, PORT), MyUDPHandler)
    server.serve_forever()

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>