Skip to content

Added WifiServer::begin(uint16_t port) method #2716

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions libraries/ESP8266WiFi/src/WiFiServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,34 @@ void WiFiServer::begin() {
tcp_arg(listen_pcb, (void*) this);
}

void WiFiServer::begin(uint16_t port) {
close();
_port = port;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something happened with indentation on this line.

err_t err;
tcp_pcb* pcb = tcp_new();
if (!pcb)
return;

ip_addr_t local_addr;
local_addr.addr = (uint32_t) _addr;
pcb->so_options |= SOF_REUSEADDR;
err = tcp_bind(pcb, &local_addr, _port);

if (err != ERR_OK) {
tcp_close(pcb);
return;
}

tcp_pcb* listen_pcb = tcp_listen(pcb);
if (!listen_pcb) {
tcp_close(pcb);
return;
}
_pcb = listen_pcb;
tcp_accept(listen_pcb, &WiFiServer::_s_accept);
tcp_arg(listen_pcb, (void*) this);
}

void WiFiServer::setNoDelay(bool nodelay) {
_noDelay = nodelay;
}
Expand Down
1 change: 1 addition & 0 deletions libraries/ESP8266WiFi/src/WiFiServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class WiFiServer : public Server {
WiFiClient available(uint8_t* status = NULL);
bool hasClient();
void begin();
void begin(uint16_t port);
void setNoDelay(bool nodelay);
bool getNoDelay();
virtual size_t write(uint8_t);
Expand Down