0
有我的webclient套接字的代碼arduino和我的java web服務器都在運行,但如何將它們連接在一起。如何將服務器連接到Arduino客戶端?
#include "Arduino.h"
#include <Ethernet.h>
#include <SPI.h>
#include <WebSocketClient.h>
byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x03};
char server[] = "localhost:8080"; // server name
WebSocketClient client;
void setup() {
Serial.begin(9600);
Ethernet.begin(mac);
client.connect(server); //client connect to the server
client.setDataArrivedDelegate(dataArrived);
client.send("Hello World!");
}
void loop() {
client.monitor();
}
如何將服務器連接到Arduino客戶端?
void dataArrived(WebSocketClient client, String data) {
Serial.println("Data Arrived: " + data);
}