2011-02-28 13:49:08 +01:00
|
|
|
#include <string.h>
|
|
|
|
#include "server_drv.h"
|
2011-05-18 15:37:29 +02:00
|
|
|
|
|
|
|
#include "WiFi.h"
|
2011-08-31 10:34:51 +02:00
|
|
|
#include "WiFiClient.h"
|
|
|
|
#include "WiFiServer.h"
|
2011-05-18 15:37:29 +02:00
|
|
|
|
|
|
|
|
2011-02-28 13:49:08 +01:00
|
|
|
|
2011-08-31 10:34:51 +02:00
|
|
|
WiFiServer::WiFiServer(uint16_t port)
|
2011-02-28 13:49:08 +01:00
|
|
|
{
|
|
|
|
_port = port;
|
|
|
|
}
|
|
|
|
|
2011-08-31 10:34:51 +02:00
|
|
|
void WiFiServer::begin()
|
2011-02-28 13:49:08 +01:00
|
|
|
{
|
|
|
|
uint8_t _sock = WiFiClass::getSocket();
|
|
|
|
if (_sock != NO_SOCKET_AVAIL)
|
|
|
|
{
|
|
|
|
ServerDrv::StartServer(_port, _sock);
|
|
|
|
WiFiClass::_server_port[_sock] = _port;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-31 10:34:51 +02:00
|
|
|
WiFiClient WiFiServer::available(byte* status)
|
2011-02-28 13:49:08 +01:00
|
|
|
{
|
|
|
|
//accept();
|
|
|
|
|
|
|
|
for (int sock = 0; sock < MAX_SOCK_NUM; sock++)
|
|
|
|
{
|
|
|
|
if (WiFiClass::_server_port[sock] != 0)
|
|
|
|
{
|
2011-08-31 10:34:51 +02:00
|
|
|
WiFiClient client(sock);
|
2011-04-21 19:16:39 +02:00
|
|
|
int _status = client.status();
|
|
|
|
if (status != NULL)
|
|
|
|
*status = _status;
|
2011-02-28 13:49:08 +01:00
|
|
|
|
|
|
|
if (WiFiClass::_server_port[sock] == _port &&
|
2011-04-21 19:16:39 +02:00
|
|
|
_status == ESTABLISHED)
|
2011-02-28 13:49:08 +01:00
|
|
|
{
|
|
|
|
return client; //TODO
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-31 10:34:51 +02:00
|
|
|
return WiFiClient(255);
|
2011-02-28 13:49:08 +01:00
|
|
|
}
|
|
|
|
|
2011-08-31 10:34:51 +02:00
|
|
|
void WiFiServer::write(uint8_t b)
|
2011-02-28 13:49:08 +01:00
|
|
|
{
|
|
|
|
write(&b, 1);
|
|
|
|
}
|
|
|
|
|
2011-08-31 10:34:51 +02:00
|
|
|
void WiFiServer::write(const uint8_t *buffer, size_t size)
|
2011-02-28 13:49:08 +01:00
|
|
|
{
|
|
|
|
for (int sock = 0; sock < MAX_SOCK_NUM; sock++)
|
|
|
|
{
|
|
|
|
if (WiFiClass::_server_port[sock] != 0)
|
|
|
|
{
|
2011-08-31 10:34:51 +02:00
|
|
|
WiFiClient client(sock);
|
2011-02-28 13:49:08 +01:00
|
|
|
|
|
|
|
if (WiFiClass::_server_port[sock] == _port &&
|
|
|
|
client.status() == ESTABLISHED)
|
|
|
|
{
|
|
|
|
client.write(buffer, size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|