Hi
Sorry posted wrong code and error!!!!also just to let you know I am new to coding !!
Sorry posted wrong code and error!!!!also just to let you know I am new to coding !!
Error:Connected by ('127.0.0.1', 52572)
b'PON'
Command Screen On Received
Traceback (most recent call last):
File "c:/Python Code/new test.py", line 55, in <module>
server()
File "c:/Python Code/new test.py", line 43, in server
udp.sendto(packet_to_sned.encode('utf-8'), (Screen_ip_address, UDP_PORT))
AttributeError: 'int' object has no attribute 'encode
import socket magic_packet_1 = 0xFFFFFFFFFFFF packet_to_sned = 0x00 Screen_mac_address = 0x00 Screen_ip_address = '' Device_2_ip_address = '' HOST = '' # Symbolic name meaning all available interfaces PORT = 50007 UDP_PORT = 9 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) udp = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.bind((HOST, PORT)) s.listen(1) filepath = 'config.cfg' with open(filepath) as fp: line = fp.readline() cnt = 1 while line: if cnt == 1: Screen_mac_address = int(line,16) print(hex(Screen_mac_address)) if cnt == 2: ip_address = line print(ip_address) if cnt == 3: Device_2_ip_address = line print(Device_2_ip_address) line = fp.readline() cnt += 1 packet_to_sned = (magic_packet_1 + Screen_mac_address ) print(packet_to_sned) def server(): conn, addr = s.accept() print ('Connected by', addr) while 1: data = str(conn.recv(1024)) print(data) if data == "b'PON'": print('Command Screen On Received') udp.sendto(packet_to_sned.encode('utf-8'), (Screen_ip_address, UDP_PORT)) if data == "b'POFF'": print('Command Screen Off Received') if not data: break conn.close() print('Disconnected', addr) while True: server()