Reads from input stream of socket into a buffer. Buffer must be provided with its length .
Or reads a record (line feed terminated) using a predefined buffer. In this case if it can't reach a line feed it stop anyway when reaches length-1 char of predefined buffer (last char for null terminator). At present LINEBUFFERLEN is 81 (see MWiFi.h file). It possible to change length.
MWiFi.readData(int socket,byte *buffer,int bufferlen)
MWiFi.readDataLn(int socket)
MWiFi.readDataLn(int socket,int millis)
socket : link socket
buffer : a byte array or a char array null terminated
bufferlen : length of buffer
millis : timeout in millisec
number of bytes really read (int) (first form)
a pointer to a null terminated string (second form)
or null if no record is still arrived
#include <MWiFi.h> //library include
MWiFi WIFI; //instance of MWiFi
int ssocket; //server socket
int csocket=0xFF; //communication socket
void setup() {
WIFI.begin(); // startup shield
:
WIFI.ConnSetOpen("DLink-casa");
int fc=WIFI.Connect();
:
ssocket=WIFI.openServerTCP(5000);
}
void loop()
{
if (csocket==255) //don't poll if link already established
{
int s=WIFI.pollingAccept(ssocket);
if (s<255) csocket=s;
}
if (csocket<255) //only when link exists
{
WIFI.writeDataLn(csocket,"Just a test");
char *line=WIFI.readDataLn(csocket);
if(line!=NULL) Serial.println(line);
}
}