0

I have I/O controller (which can turn on/off the lights) connect to the server (digitalocean running on ubuntu) using TCP/IP protocol. I/O controller acts as a client. I have python script listening connections from clients. This python script path /root/tcp_socket/server_socket.py

server_socket.py

from socket import socket, AF_INET, SOCK_STREAM, SOL_SOCKET, SO_REUSEADDR
import _thread
import time
import datetime

host = '0.0.0.0'
port = 8080
buf = 1024

addr = (host, port)

serversocket = socket(AF_INET, SOCK_STREAM)
serversocket.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
serversocket.bind(addr)
serversocket.listen(10)

clients = [serversocket]


def handler(clientsocket, clientaddr):
    print("Accepted connection from: ", clientaddr)
    while True:
         data = clientsocket.recv(1024)

while True:
   try:
       print("Server is listening for connections\n")
       clientsocket, clientaddr = serversocket.accept()
       clients.append(clientsocket)
       _thread.start_new_thread(handler, (clientsocket, clientaddr))
   except KeyboardInterrupt: 
       print("Closing server socket...")
       serversocket.close()

I have web site which is built on python Flask framework running on ubuntu. In my website has toggle buttons such as turn on and turn off. Turn on and turn off toggles. path /var/www/FlaskApp/FlaskApp/

My question is how can I access from web page to connected clients which can handle by using server_socket.py.And how can I send "On" command to the I/O controller when on toggle clicked

0 Answers0