python和websockets的新手,但我正在尝试执行以下操作:
import httplib
conn = httplib.HTTPConnection('localhost:8888')
conn.putheader('Connection', 'Upgrade')
conn.putheader('Upgrade', 'websocket')
conn.endheaders()
conn.send('Hello to websocket!')
到达putheader时崩溃
服务器代码是用Node.js编写的
var http = require('http');
http.createServer(function (request, response) {
console.log(request);
}).on('upgrade', function(request, socket, head) {
console.log('Upgrade request! Woohoo!');
socket.connect(8080, 'localhost', function(data) {
console.log('data');
});
socket.write('Socket is open!');
}).listen(8888);
并不是真的担心服务器代码是正确的(如果我需要从我的Python客户端发送请求,我会修复它),但我想知道如何使用httplib升级到websocket的连接(如果有可能)。