Код: Выделить всё
#!/usr/bin/env python
from socket import *
HOST = ''
PORT = 8080
BUFSIZ = 1024
ADDR = (HOST, PORT)
tcpSerSock = socket(AF_INET, SOCK_STREAM)
tcpSerSock.bind(ADDR)
tcpSerSock.listen(5)
def loop():
while True:
print 'Waiting for connection...'
tcpCliSock, addr = tcpSerSock.accept()
print '...connected from :', addr
while True:
data = tcpCliSock.recv(BUFSIZ)
if not data:
break
else:
print 'data: ',data
tcpSerSock.close()
try:
loop()
except KeyboardInterrupt:
tcpSerSock.close()
Код: Выделить всё
Waiting for connection...
Traceback (most recent call last):
File "ledServer.py", line 27, in
loop()
File "ledServer.py", line 16, in loop
tcpCliSock, addr = tcpSerSock.accept()
File "/usr/lib/python2.7/socket.py", line 202, in accept
sock, addr = self._sock.accept()
File "/usr/lib/python2.7/socket.py", line 170, in _dummy
raise error(EBADF, 'Bad file descriptor')
socket.error: [Errno 9] Bad file descriptor
Код: Выделить всё
window.onload = function(){
ws = new WebSocket('ws://192.168.25.7:8080');
ws.onmessage = function(event){document.write("message received"); alert(event.data); ws.close();}
ws.onopen = function(){document.write("open");}
ws.onclose = function(){document.write("close");}
ws.onerror = function(){document.write("error");}
}
Код: Выделить всё
...connected from : ('192.168.25.25', 53747)
data: GET / HTTP/1.1
Host: 192.168.25.7:8080
Connection: Upgrade
Pragma: no-cache
Cache-Control: no-cache
Upgrade: websocket
Origin: file://
Sec-WebSocket-Version: 13
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36
Accept-Encoding: gzip, deflate
Accept-Language: it-IT,it;q=0.9,en-US;q=0.8,en;q=0.7,tr;q=0.6,nl;q=0.5
Sec-WebSocket-Key: pH4kNOzz1MYyi+oXmaFCcA==
Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits
Код: Выделить всё
Uncaught DOMException: Failed to execute 'send' on 'WebSocket': Still in CONNECTING state.
Подробнее здесь: https://stackoverflow.com/questions/485 ... ket-server