Skip to content

Commit 2ea7dd5

Browse files
author
JeromeGalan
authored
Merge pull request #173 from Luos-io/rc_2.2.8
Pyluos Release 2.2.8
2 parents a349582 + f92bbc8 commit 2ea7dd5

File tree

3 files changed

+218
-135
lines changed

3 files changed

+218
-135
lines changed

pyluos/io/ws.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import socket
33
import websocket
4+
import struct
45

56
import sys
67
if sys.version_info >= (3, 0):
@@ -16,7 +17,6 @@ def resolve_hostname(hostname, port):
1617
# to enforce we only search for IPV4 address
1718
# and avoid a 5s timeout in the websocket on the ESP
1819
# See https://github.com/esp8266/Arduino/issues/2110
19-
2020
addrinfo = socket.getaddrinfo(hostname, port,
2121
socket.AF_INET, 0,
2222
socket.SOL_TCP)
@@ -32,7 +32,7 @@ def is_host_compatible(cls, host):
3232
socket.inet_pton(socket.AF_INET, host)
3333
return True
3434
except socket.error:
35-
return host.endswith('.local')
35+
return host.endswith('.local') or (host == "localhost")
3636

3737
@classmethod
3838
def available_hosts(cls):
@@ -47,8 +47,8 @@ def available_hosts(cls):
4747
def __init__(self, host, port=9342):
4848
host = resolve_hostname(host, port)
4949

50-
self._ws = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
51-
self._ws.connect((host, port))
50+
self._ws = websocket.WebSocket()
51+
self._ws.connect("ws://" + str(host) + ":" + str(port)+"/ws")
5252

5353
self._msg = queue.Queue(500)
5454
self._running = True
@@ -68,7 +68,7 @@ def recv(self):
6868
return data
6969

7070
def write(self, data):
71-
self._ws.send(data + '\r'.encode() + '\n'.encode())
71+
self._ws.send(data)
7272

7373
def close(self):
7474
self._running = False
@@ -92,8 +92,7 @@ def extract_line(s):
9292
buff = b''
9393

9494
while self._running:
95-
s = self._ws.recv(4096)
96-
95+
s = self._ws.recv()
9796
buff = buff + s
9897
while self._running:
9998
line, buff = extract_line(buff)

0 commit comments

Comments
 (0)