Skip to content

Commit 04919f8

Browse files
committed
only try to send socket.io messages in WSC_CONNECTED state
handle sIOtype_CONNECT messages send 2probe on websocket connect (#574)
1 parent 2531811 commit 04919f8

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/SocketIOclient.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ bool SocketIOclient::send(socketIOmessageType_t type, uint8_t * payload, size_t
8181
if(length == 0) {
8282
length = strlen((const char *)payload);
8383
}
84-
if(clientIsConnected(&_client)) {
84+
if(clientIsConnected(&_client) && _client.status == WSC_CONNECTED) {
8585
if(!headerToPayload) {
8686
// webSocket Header
8787
ret = WebSocketsClient::sendFrameHeader(&_client, WSop_text, length + 2, true);
@@ -165,6 +165,7 @@ void SocketIOclient::handleCbEvent(WStype_t type, uint8_t * payload, size_t leng
165165
DEBUG_WEBSOCKETS("[wsIOc] Connected to url: %s\n", payload);
166166
// send message to server when Connected
167167
// Engine.io upgrade confirmation message (required)
168+
WebSocketsClient::sendTXT("2probe");
168169
WebSocketsClient::sendTXT(eIOtype_UPGRADE);
169170
runIOCbEvent(sIOtype_CONNECT, payload, length);
170171
} break;
@@ -195,6 +196,8 @@ void SocketIOclient::handleCbEvent(WStype_t type, uint8_t * payload, size_t leng
195196
DEBUG_WEBSOCKETS("[wsIOc] get event (%d): %s\n", lData, data);
196197
break;
197198
case sIOtype_CONNECT:
199+
DEBUG_WEBSOCKETS("[wsIOc] connected (%d): %s\n", lData, data);
200+
return;
198201
case sIOtype_DISCONNECT:
199202
case sIOtype_ACK:
200203
case sIOtype_ERROR:

0 commit comments

Comments
 (0)