I have been bashing my head all day with this sockets stuff.
What I would like is for someone to show me how to achieve a simple sockets app that has the ESP32 as a client and connecting to a server. BUT, here is my issue....gefore I show you how far I have got with the Arduino code, let me give you some background...
What I have, is a socket server running on my hosting service, and i have created a IIS app that consumes a socket request. I have it running smoothly if I use my browser to connect and send messages. Here is the javascript that essentially send the connect request from my browser to the server:
Code: Select all
var connection = new WebSocket("ws://" + location.host + "/chat/wsock.ashx?UN=" + yrname);
connection.onmessage = function (message) {
var data = window.JSON.parse(message.data);
//alert(data.mBody);
$("<li/>").html(data.mBody).appendTo($("#messages"));
};
Now, what I amtrying to do is to connect to the same server, with the ESP32 and send the same querystring as above.
When I try this code on the ESP32, it works in that it doesnt fail, so I assume it has made the sockets connection. (But of course it sets no querystring):
Code: Select all
struct addrinfo hints, *res;
int sockfd;
memset(&hints, 0, sizeof hints);
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
if (getaddrinfo("www.itbpaul.co.za", "80", &hints, &res))
{
Serial.println("fail at getaddrinfo");
}
// make a socket:
if (
sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)
) {
Serial.println("fail at socket");
}
// connect!
if (connect(sockfd, res->ai_addr, res->ai_addrlen))
{
Serial.println("no connect");
}
i Have also tried appending this to the end to no avail:
Code: Select all
char *msg = "GET ws://itbpaul.co.za/chat/wsock.ashx?UN=psdsd \n\n";
int len, bytes_sent;
len = strlen(msg);
bytes_sent = send(sockfd, msg, len, 0);
Serial.println("all ok");
Serial.println(bytes_sent);
I have also read the following articles to try get more background but I am stuck:
https://www.youtube.com/watch?v=KyCZh9NcinI
http://www.tcpipguide.com/free/t_HTTPRe ... Format.htm
https://www.freebsd.org/doc/en_US.ISO88 ... tions.html
http://esp32.info/docs/esp_idf/html/d4/ ... ource.html
http://beej.us/guide/bgnet/output/print/bgnet_A4.pdf
Regards and thanks
Paul