![](/img/trans.png)
[英]can't send packets from arduino to python client using UDP socket over ethernet
[英]Arduino fails to connect with ethernet client
在此GET请求中,我不需要服务器的答复,因此循环功能为空。
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
IPAddress ip;
byte localIp[] = {192,168,1,181};
EthernetClient client;
void setup()
{
Serial.begin(9600);
Ethernet.begin(mac , localIp);
delay(1000);//give ethernet time to boot?
byte x[] = { 192,168,1,1 };//my pc , running SimpleHTTPServer (python)
client.connect(x , 8000);
delay(1000);
if(client.connected()){
Serial.println("connected"); //does never print
}
}
void loop()
{
}
我的电脑的网络服务器未收到任何连接请求。
您的样本甚至无法编译。 这里是固定版本。
连接后,最好与client.stop()紧密连接,否则某些简单的服务器可能不会在侦听新的连接,而仍在等待来自先前连接的数据。
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
IPAddress ip;
IPAddress localIp (192,168,1,181);
EthernetClient client ;
void setup()
{
Serial.begin(9600);
Ethernet.begin(mac , localIp);
char x[] = "192.168.1.1" ;//my pc , running SimpleHTTPServer (python)
client.connect(x , 8000);
if( client.connected() ){
Serial.println("connected"); //does never print
}
client.println ("Hellou world from Arduino!") ;
client.stop();
}
void loop()
{
}
米哈尔
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.