Skip to content
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

Add possibility to change server tcp port in void setup. No more fixed port! #39

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

5a2v0
Copy link

@5a2v0 5a2v0 commented Aug 4, 2016

Before this modification:

EthernetServer server(80);
void setup() {
//some stuff here
server.begin(); //User can't change initial port value
//other stuff here
}

Now:

EthernetServer server; //without port declaration but still working old declaration system...
void setup() {
//some stuff here
unsigned int tcp = EEPROM.read(x)
server.begin(tcp); //User can now use a different port, maybe saved in eprom directly from the sketch in a configuration page that permise to choice a value for the tcp port...
//other stuff here
}

Many thanks to Arduino's forum user: SukkoPera

…d port!

Before this mofication:

EthernetServer server(80);
void setup() {
//some stuff here
server.begin(); //User can't change initial port value
//other stuff here
}

Now:

EthernetServer server; //without port declaration but still working old declaration system...
void setup() {
//some stuff here
unsigned int tcp = EEPROM.read(x)
server.begin(tcp); //User can now use a different port, maybe saved in eprom directly from the sketch in a configuration page that permise to choice a value for the tcp port...
//other stuff here
}

Many thanks to Arduino's forum user: SukkoPera
@sandeepmistry
Copy link

sandeepmistry commented Aug 11, 2016

Hi @5a2v0,

Thanks for submitting this.

I'm wondering if the following is a better way to achieve the same functionality without changing the API. I'm concerned about fragmenting the API, because other network libraries that extend Server (like WiFi101) would not have the change.

int port = 80; // default port
EthernetServer server(port);

void setup() {
  //some stuff here

  port = EEPROM.read(x);

  if (port > 0) {
    server = EthernetServer(port); // change the port
  }

  server.begin(); //User can now use a different port, maybe saved in eprom directly from the sketch in a configuration page that permise to choice a value for the tcp port...

  //other stuff here
}

@zoomx
Copy link

zoomx commented Sep 9, 2016

@sandeepmistry
maybe you mean server.begin(); instead of server.begin(tcp);?

@sandeepmistry
Copy link

@zoomx yes, sorry. I will update my previous comment.

@CLAassistant
Copy link

CLAassistant commented Apr 9, 2021

CLA assistant check
All committers have signed the CLA.

@per1234 per1234 linked an issue Apr 20, 2022 that may be closed by this pull request
@JAndrassy
Copy link
Contributor

In the newest WiFi library WiFiS3 for the Uno R4, Arduino has begin(port) and ctor without parameter, which I guess officially introduces it into the Arduino networking API.

overview of Server implementations in libraries https://github.com/JAndrassy/Arduino-Networking-API/blob/main/ArduinoNetAPILibs.md#server-class

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add EthernetServer() {} constructor
5 participants