inventree-phomemo-plugin/inventree_phomemo/server.py

23 lines
516 B
Python
Raw Normal View History

# server.py
# simple listener to an IP port to test the phomemo plugin
import socket
PORT = 9100 # Port to listen on
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('', PORT))
s.listen(1)
while True:
conn, addr = s.accept()
print(addr)
while True:
data = conn.recv(9100)
print('data received')
print('Sending to printer...')
printer=open('test.png','wb')
printer.write(data)
printer.close()
if not data:
break