I am using the Arduino Websocket Client library to connect my Arduino Uno to a Socket.IO server. But the connection always returns 0 (fail) after the handshake. Anyone has used this library before? How could I debug this?
#include "Arduino.h"
#include <Ethernet.h>
#include <SPI.h>
#include <WebSocketClient.h>
byte mac[] = {0xB8,0x27,0xEB,0x7E,0x2D,0xC9};
char server[] = "labathome.rexlab.ufsc.br";
int port = 8001;
WebSocketClient client;
void setup() {
Serial.begin(9600);
Ethernet.begin(mac);
Serial.println(client.connect(server, port));
client.setDataArrivedDelegate(dataArrived);
client.send("Hello World!");
}
void loop() {
client.monitor();
}
void dataArrived(WebSocketClient client, String data) {
Serial.println("Data Arrived: " + data);
}
PS: I tested the server and it works fine, and I also tested with a normal WS server instead of the Socket.IO, and nothing :(
-
Wireshark is a nice tool for protocol analysis.Mikael Patel– Mikael Patel2017年01月11日 09:20:26 +00:00Commented Jan 11, 2017 at 9:20
-
I know nothing about this library but it looks like the setup of your Arduino is incorrect. What IP address has your Arduino got? Where is the DNS server to resolve the server's address and how are you telling the Arduino this? Does it work if you use the IP Address rather than the name for the server?Code Gorilla– Code Gorilla2017年01月11日 13:27:38 +00:00Commented Jan 11, 2017 at 13:27
-
And like @MikaelPatel says, download wireshark (or similar) and verify that the Arduino is connecting to the server. (You might be able to see the server's logs). I suspect it isn't.Code Gorilla– Code Gorilla2017年01月11日 13:28:48 +00:00Commented Jan 11, 2017 at 13:28
-
@MikaelPatel how could I forget about wireshark! ThanxJosé Pedro Simão– José Pedro Simão2017年01月11日 13:51:47 +00:00Commented Jan 11, 2017 at 13:51
-
1@Matt oops, true. I am using DHCP (I'm printing the IP got by the Arduino here), and I usually use IP addresses rather than the name, my bad.José Pedro Simão– José Pedro Simão2017年01月11日 13:54:53 +00:00Commented Jan 11, 2017 at 13:54
1 Answer 1
With the help of the library developer, I found out that it was a problem on the handshake version. So, I just downgraded my socket.io app from 1.0 to v 0.9.11 and it worked.
-
What version were you using? (What version has the handshaking problem?) - Useful in case anyone searches and lands on this thread. Also its OK to accept your own answer.Code Gorilla– Code Gorilla2017年01月13日 09:28:16 +00:00Commented Jan 13, 2017 at 9:28
Explore related questions
See similar questions with these tags.