error 1006
gfduck opened this issue · 13 comments
I use example of simple client websocket, in localhost works correctly but in my hosting appear error 1006.
The Arduino connect and desconnect after 1 second in Server.
Can you help me?
This is my code:
#include <WebSocketClient.h>
using namespace net;
byte mac[]{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
# define _SERIAL Serial
WebSocketClient client;
void setup() {
_SERIAL.begin(9600);
Ethernet.begin(mac); //, ip);
_SERIAL.print(F("Device IP: "));
_SERIAL.println(Ethernet.localIP());
client.onOpen([](WebSocket &ws) {
_SERIAL.println(F("Connected"));
constexpr char message[]{ "Hello from Arduino client!" };
ws.send(WebSocket::DataType::TEXT, message, strlen(message));
});
client.onMessage([](WebSocket &ws, const WebSocket::DataType &dataType,
const char *message, uint16_t length) {
switch (dataType) {
case WebSocket::DataType::TEXT:
_SERIAL.println(F("Received text message"));
_SERIAL.println(message);
break;
case WebSocket::DataType::BINARY:
_SERIAL.println(F("Received binary data"));
break;
}
ws.send(dataType, message, length); // echo back to server
});
client.onClose(
[](WebSocket &ws, const WebSocket::CloseCode &code, const char *reason,
uint16_t length) { _SERIAL.println(F("Disconnected")); });
if (!client.open("server.com", 80, "/chat")) {
_SERIAL.println(F("Connection failed!"));
while (true)
;
}
}
void loop() { client.listen(); }
Hi @gfduck
Could you post arduino log?
Is your server ws or wss?
Please enable debug macros in config.h
Thanks for answer!.
This is file config.h, how to enable enable debug macros?
Can you send the correct content of file?
Thanks!
#pragma once
/** @file */
/**
* @def _DEBUG Enables __debugOutput function.
* @def _DUMP_HANDSHAKE Prints any handshake request/response on Serial output.
* @def _DUMP_HEADER Prints frame header on Serial output.
* @def _DUMP_FRAME_DATA Prints frame data on Serial output.
*/
/**
* @def NETWORK_CONTROLLER
* @brief Specifies network controller, available values:
* - ETHERNET_CONTROLLER_W5X00
* - ETHERNET_CONTROLLER_ENC28J60
* - NETWORK_CONTROLLER_WIFI
*/
//#define _DEBUG
//#define _DUMP_HANDSHAKE
//#define _DUMP_HEADER
//#define _DUMP_FRAME_DATA
#define NETWORK_CONTROLLER ETHERNET_CONTROLLER_W5X00
/** Maximum size of data buffer - frame payload (in bytes). */
constexpr uint16_t kBufferMaxSize{ 256 };
/** Maximum time to wait for endpoint response (in milliseconds). */
constexpr uint16_t kTimeoutInterval{ 5000 };
My server is ws
Just uncomment these four defines. Are you trying to connect by passing ip address or http://?
Ok, now it's clear.
Go into WebSocketClient.cpp
and replace strcmp_P
with strcasecmp_P
in the line 172.
In webserver is error 1002
Any debug message?
During this days I will do some test on the library and I will let you know! I am so thankful for your help
You're welcome.