使用 CC3000 和 socket.io 创建 websocket 时,服务器不发送 HTTP 101 响应 [英] Server not sending HTTP 101 response when creating a websocket using CC3000 and socket.io

查看:38
本文介绍了使用 CC3000 和 socket.io 创建 websocket 时,服务器不发送 HTTP 101 响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 socket.io 将 CC3000 连接到 node.js 服务器.我使用以下库创建了一个 websockethttps://github.com/chadstachowicz/socket_io_arduino_cc3000

I am connecting CC3000 to a node.js server using socket.io. I have used the following library to create a websocket https://github.com/chadstachowicz/socket_io_arduino_cc3000

在 SocketIOClient.cpp 中,它创建一个 TCP 连接,获取一个 session-id(sid).它断开连接并创建另一个 TCP 连接,并使用 sid 将连接升级到 websocket.为此,客户端(此处为 CC3000)发送以下标头信息:

In SocketIOClient.cpp, it creates a TCP connection, gets a session-id(sid). It disconnects and creates another TCP connection and uses the sid to upgrade the connection to websocket. For this the client(here CC3000) sends the following header information:

client.print(F("GET /socket.io/1/websocket/"));
client.print(sid);
client.println(F(" HTTP/1.1"));
client.print(F("Host: "));
client.println(hostname);
client.println(F("Origin: ArduinoSocketIOClient"));
client.println(F("Upgrade: WebSocket"));    // must be camelcase ?!
client.println(F("Connection: Upgrade\r\n"));

在此请求之后,客户端等待来自服务器的 HTTP 101 响应.但是服务器没有发送任何响应.它记录为警告websocket 连接无效"并结束连接.

After this request the client waits for HTTP 101 response from the server. But the server is not sending any response. It logs as warning "websocket connection invalid" and ends the connection.

创建 websocket 的协议是否正常,或者头部是否缺少任何信息?

Is the protocol for creating websocket fine or is there any missing information in the header?

另外,我想知道'Origin'的值应该是多少?在第一次握手时它是Arduino",而在第二次握手时它是ArduinoSocketIOClient".

Also, I want to know what should the value of 'Origin' be? During first handshake it is "Arduino" whereas in the second handshake it is "ArduinoSocketIOClient".

推荐答案

您缺少 Sec-WebSocket-KeySec-WebSocket-Version 标头,关键部分WebSocket 协议握手.

You are missing the Sec-WebSocket-Key and Sec-WebSocket-Version headers, key part of the WebSocket protocol handshake.

这是实际握手的样子:

GET /chat HTTP/1.1
Host: server.example.com
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Key: x3JJHMbDL1EzLkh9GBhXDw==
Sec-WebSocket-Protocol: chat, superchat
Sec-WebSocket-Version: 13
Origin: http://example.com

这篇关于使用 CC3000 和 socket.io 创建 websocket 时,服务器不发送 HTTP 101 响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆